Skip to content

Conversation

@samsonasik
Copy link
Member

@samsonasik samsonasik commented Sep 15, 2022

Given the following code:

final class SkipNestedInPhp80
{
    /**
     * @Assert\All({
     *     @Assert\Uuid()
     * })
     */
    public array $selected = [];
}

with set config for PhpVersionFeature::NEW_INITIALIZERS - 1 or Phpversion::PHP_80

return static function (RectorConfig $rectorConfig): void {
    $rectorConfig->phpVersion(PhpVersionFeature::NEW_INITIALIZERS - 1);

    $rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
        new AnnotationToAttribute(All::class),
    ]);
};

It currently cause crash:

There was 1 error:

1) Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Php80NestedAttributesRectorTest::test with data set #0 ('/Users/samsonasik/www/rector-...hp.inc')
TypeError: PhpParser\Node\Expr\ArrayItem::__construct(): Argument #1 ($value) must be of type PhpParser\Node\Expr, string given, called in /Users/samsonasik/www/rector-src/packages/PhpAttribute/AnnotationToAttributeMapper/ArrayItemNodeAnnotationToAttributeMapper.php on line 63

Fixes rectorphp/rector#7480

@samsonasik
Copy link
Member Author

Fixed 🎉 /cc @mkalkowski83 , it was tried to apply nested new initializer, while it only exists in php 8.1, if the config is set php version to php 8.0, it should be skipped.

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@mkalkowski83
Copy link

WOW! thank you for reaction so quickly 💪

@TomasVotruba TomasVotruba merged commit cec7701 into main Sep 15, 2022
@TomasVotruba TomasVotruba deleted the fix-7480 branch September 15, 2022 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error on parsing file

5 participants