Skip to content

Conversation

@simonschaufi
Copy link
Contributor

No description provided.

{
/**
* @var string
* @TYPO3\CMS\Extbase\Annotation\Validate("NotEmpty")
Copy link
Member

@samsonasik samsonasik Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I already stated in your other PR, using namespaced annotation inside namespace will become; namespace + annotation. If you need fqcn without \\, add:

use TYPO3;

in use statements or create rule/script init that add \\ prefix early to become;

@\TYPO3\...

Just because in one condition it works, in another condition not works, doesn't mean the original annotation is valid.

Copy link
Contributor Author

@simonschaufi simonschaufi Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just because in one condition it works, in another condition not works, doesn't mean the original annotation is valid.

The question is why is this the case? I know this needs some debugging but there must be something going on why there is a difference. If we find the place, I can provide a fix. It's just very difficult to understand the php doc parsing. Maybe @TomasVotruba has an idea as he originally created the better doc block parser.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how PHP uses namespaces. Either add use TYPO; or use \\ to FQN the class.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we only use https://github.com/phpstan/phpdoc-parser here with a bit of wrapping. So the cause might be there.

Copy link
Contributor Author

@simonschaufi simonschaufi Sep 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is how PHP uses namespaces. Either add use TYPO; or use \ to FQN the class.

This was the official TYPO3 way of annotating. I can't just tell everybody to adjust their code. That's why I built a rule to migrate that to a native php attribute. The transformation to a php attribute also works as long as there is no @var string annotation. For some reason this additional annotation is causing problems and I'm trying to figure out why.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That can be behaviour of PHPStan\Analyser\NameScope that unrelated to Rector.

The best way is to add use TYPO3 in your use statements.

For your usecase in case you still want the way it is, you probably needs to implements your own PhpDocNodeDecoratorInterface instance, and decorate resolved_class attribute, special for TYPO3 annotation, then you can replace by its resolved_class value.

interface PhpDocNodeDecoratorInterface
{
public function decorate(PhpDocNode $phpDocNode, Node $phpNode): void;
}

see examples on existing decorator

https://github.com/rectorphp/rector-src/tree/d64f8d876c66cd2def70e603ef1125eb6be2d64c/src/BetterPhpDocParser/PhpDocParser

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I'm gonna try this out.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simonschaufi I got it, it seems needs tweak on IdentifierPhpDocTypeMapper to not replace the existing IdentifierTypeNode on visit, then verify on auto import handling docblock, see PR:

samsonasik added a commit that referenced this pull request Sep 26, 2025
samsonasik added a commit that referenced this pull request Sep 26, 2025
* Add example for issue #9388

* Closes #7330

* [ci-review] Rector Rectify

* Fix phpstan

* clean up fixture

* [ci-review] Rector Rectify

---------

Co-authored-by: Simon Schaufelberger <simonschaufi@users.noreply.github.com>
Co-authored-by: GitHub Action <actions@github.com>
@simonschaufi simonschaufi deleted the issue-9388 branch September 26, 2025 10:43
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.

3 participants