Skip to content

[make:entity] Crash when return type from DoctrineHelper is mixed #1612

@pkly

Description

@pkly

Hello,

I'm able to reliably crash the make:entity command on 1.61 because of the following line:

return $returnType->isBuiltin() ? $returnType->getName() : '\\'.$returnType->getName();

As this helper relies on the convertToPHPValue return type (very clever btw) it will crash if the return value is set to mixed. This can be replicated with any custom doctrine type that is set in the application, with the following stack trace.

in BuilderHelpers.php line 208:
                                 
  [LogicException]               
  mixed type cannot be nullable  
                                 

Exception trace:
  at /var/www/vendor/nikic/php-parser/lib/PhpParser/BuilderHelpers.php:208
 PhpParser\BuilderHelpers::normalizeType() at /var/www/vendor/nikic/php-parser/lib/PhpParser/Builder/Property.php:127
 PhpParser\Builder\Property->setType() at /var/www/vendor/symfony/maker-bundle/src/Util/ClassSourceManipulator.php:402
 Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator->addProperty() at /var/www/vendor/symfony/maker-bundle/src/Util/ClassSourceManipulator.php:151
 Symfony\Bundle\MakerBundle\Util\ClassSourceManipulator->addEntityField() at /var/www/vendor/symfony/maker-bundle/src/Maker/MakeEntity.php:243
 Symfony\Bundle\MakerBundle\Maker\MakeEntity->generate() at /var/www/vendor/symfony/maker-bundle/src/Command/MakerCommand.php:102
 Symfony\Bundle\MakerBundle\Command\MakerCommand->execute() at /var/www/vendor/symfony/console/Command/Command.php:326

It appears that the builder tries to make a field with type mixed|null or ?mixed but mixed already implicitly includes null, which causes the error.

After updating the return type for our custom type from mixed to a more sensible string|null the error has stopped. Maybe in such a case a note should be printed to cli?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions