Problem/Motivation
Coder complains with:
Data types in @var tags need to be fully namespaced (Drupal.Commenting.DataTypeNamespace.DataTypeNamespace)
When using PHPStan type imports https://phpstan.org/writing-php-code/phpdoc-types#local-type-aliases
Steps to reproduce
Define or import a type
Use the type in /** @var MyType $variableName */
Proposed resolution
Never complain about PHPStan types.
Instead of adding PHPStan specific functionality, perhaps coder should instead check if the class exists in the same namespace as the file, before complaining about non FQN's. This would mean that a type not defined as a class AND phpstan would not throw an error, but I think thats fine. The sniff is testing about FQN, not type or class-existence. If we want sniffs ensuring existence, then that should be the responsibility of a different sniff.
Comments
Comment #2
dpiComment #3
klausiThanks for reporting!
Can you put a full code example where the problem triggers in the issue summary?
I tried to reproduce with this, but works fine for me:
What am I doing wrong?
Side note: Coder cannot check if classes exist. It is coding standards checker that cannot access/process other PHP files to check if classes exist. We are deliberately leaving that to PHPStan.
As far as I understand our DataTypeNamespaceSniff it only checks that if a type matches the use statement, then the FQN should be used.
Comment #4
dpiThe error is present on https://git.drupalcode.org/project/pinto_theme/-/blob/1.x/src/EventListe...
Comment #5
mxr576I have just came across the same issue and the example from #4 proves the problem.
In addition
Fooin@phpstan-paramalso gets changed to FQCN.Comment #6
klausiThis was fixed in Coder 9 and the sniff DataTypeNamespace removed.
Please test and let me know if this is still an issue!
Note that we are also dropping FQN checks in data type comments in #3360163: Stop using FQCN in @param @var @return annotations, that should land soon.
Comment #9
wim leersIt still is an issue: #3607093: DataTypeNamespace complains about namespace when PHPStan types are *imported* using `@phpstan-import-type` then used — and I have a theory! 🤓