Skip to content
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

Error with PHP8 and __toString for Symfony project when use DoctrineBehaviors translation on entities #5497

Closed
RomulusED69 opened this issue Aug 21, 2021 · 8 comments

Comments

@RomulusED69
Copy link

Bug report

Hi ✋,

I have a Symfony project with https://github.com/KnpLabs/DoctrineBehaviors.
I tried to update project to PHP8 but I'm having problem with phpstan.

Bundle created its own extensions https://github.com/KnpLabs/DoctrineBehaviors/tree/master/utils/phpstan-behaviors/src/Type

No problem with PHP7.4 but with PHP8:
Sélection_152
Sélection_153

After investigations, problem occurs only when method __toString is defined.
Problem appears on invoke here https://github.com/KnpLabs/DoctrineBehaviors/blob/master/utils/phpstan-behaviors/src/Type/TranslationTypeHelper.php#L36

Code snippet that reproduces the problem

https://github.com/RomulusED69/phpstan-knp-doctrine-behaviors-bug

Thanks for your help

@mergeable
Copy link

mergeable bot commented Aug 21, 2021

This bug report is missing a link to reproduction on phpstan.org.

It will most likely be closed after manual review.

@ondrejmirtes
Copy link
Member

Fixed: ondrejmirtes/BetterReflection@fef40df + phpstan/phpstan-src@89ceb6a

@RomulusED69
Copy link
Author

Thank you

@RomulusED69
Copy link
Author

After testing, it turns out that it does not work.
In my example, TranslatableMethodsTrait, in context of Article, should return ArticleTranslation but return now Knp\DoctrineBehaviors\Model\Translatable\TranslatableMethodsTraitTranslation.

Sélection_154

TranslatableMethodsTrait use return static::class . 'Translation';

@ondrejmirtes

@ondrejmirtes
Copy link
Member

ondrejmirtes commented Aug 22, 2021

Hi, this is not a PHPStan bug. Looks like the extension is saying that translate() method returns TranslatableMethodsTraitTranslation, and such class does not exist. This needs to be fixed in the extension. Most likely TranslatableTranslateDynamicMethodReturnTypeExtension.

@RomulusED69
Copy link
Author

I'm not sure.
In extension, first, they create reflexionClass like this

$reflectionClass = $broker->getClass($translatableClass)
            ->getNativeReflection();

with $translatableClass = 'Article';

$reflectionClass
            ->getMethod('getTranslationEntityClass')
            ->invoke(null);

should return ArticleTranslation but reflexion behaves as if the trait was alone without context of Article.

return static::class . 'translation'; in context of Article with Trait should return for static::class => Article but reflexion return Trait

@ondrejmirtes
Copy link
Member

@RomulusED69 Fixed that too :) ondrejmirtes/BetterReflection@f14002e + phpstan/phpstan-src@9b51f82

@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants