rectorphp / rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
https://getrector.com
MIT License
8.67k stars 682 forks source link

Normalization failure with AnnotationToAttributeRector #6500

Closed romainallanot closed 3 years ago

romainallanot commented 3 years ago

Bug Report

Subject Details
Rector version e.g. v0.11.16

PHP Fatal error: Uncaught LogicException: Invalid value in rector/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php:220 when value is an instance of PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprFalseNode.

Minimal PHP Code Causing Issue

<?php

use ApiPlatform\Core\Annotation\ApiResource;

/**
 * @ApiResource(
 *     collectionOperations={},
 *     itemOperations={
 *         "get",
 *         "get_by_isbn"={"method"="GET", "path"="/books/by_isbn/{isbn}.{_format}", "requirements"={"isbn"=".+"}, "identifiers"="isbn"}
 *     },
 *     graphql={
 *         "sumOnlyPersist"={
 *             "mutation"="app.graphql.mutation_resolver.dummy_custom_only_persist",
 *             "normalization_context"={"groups"={"result"}},
 *             "denormalization_context"={"groups"={"sum"}},
 *             "read"=false,
 *             "deserialize"=false,
 *             "validate"=false,
 *             "serialize"=false
 *          }
 *     }
 * )
 */
class ApiPlatformResource {}
<?php

use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $services = $containerConfigurator->services();

    $services->set(AnnotationToAttributeRector::class)
        ->call('configure', [[
            AnnotationToAttributeRector::ANNOTATION_TO_ATTRIBUTE => ValueObjectInliner::inline([
                new AnnotationToAttribute(
                    'ApiPlatform\Core\Annotation\ApiResource',
                    'ApiPlatform\Core\Annotation\ApiResource'
                ),
            ]),
        ]]);
};

Expected Behaviour

Normalize array node values in PhpAttributeFactory

samsonasik commented 3 years ago

It seems fixed at https://github.com/rectorphp/rector-src/pull/190