8000 [make:entity] Crash when return type from DoctrineHelper is mixed · Issue #1612 · symfony/maker-bundle · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pkly opened this issue Nov 8, 2024 · 2 comments · Fixed by #1619
Closed

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

pkly opened this issue Nov 8, 2024 · 2 comments · Fixed by #1619

Comments

@pkly
Copy link
pkly commented Nov 8, 2024

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?

@mdoutreluingne
Copy link
Contributor

Hello,

How can we reproduce the bug with make:entity command?

@pkly
Copy link
Author
pkly commented Nov 17, 2024

As I've pointed out above, you can trigger the crash by changing the return type of convertToPHPValue to mixed on the doctrine type class you're using while selecting the field.

For example, you could modify the built-in string column type for doctrine to return that from said method. A crash should occur then.

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 a pull request may close this issue.

2 participants
0