Skip to content

[PHP 8.5] ClosureToArrowFunctionRector should not touch closure inside attribute #9598

@ruudk

Description

@ruudk

Bug Report

Subject Details
Rector version e.g. v1.0.0 (invoke vendor/bin/rector --version)

https://www.php.net/releases/8.5/en.php#closures-in-const-expr

The following code:

class SomeHandler
{
    #[Idempotency(key: static function(Command $command) : IdempotencyKey { 
        return new IdempotencyKey(
           'key',
        );
    }, seconds: 604_800)]
    public function __invoke(Command $command) : void
    {}
}

Is changed by ClosureToArrowFunctionRector:

    ---------- begin diff ----------
     #[AsCommandHandler]
-    #[Idempotency(key: static function(Command $command) : IdempotencyKey { return new IdempotencyKey(
+    #[Idempotency(key: static fn(Command $command): IdempotencyKey => new IdempotencyKey(
         'key',
-    );}, seconds: 604_800)]
+    ), seconds: 604_800)]
     public function __invoke(Command $command) : void
     {
    ----------- end diff -----------

Applied rules:
 * ClosureToArrowFunctionRector

But this is not allowed. fn is not allowed inside attributes.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions