You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was wondering if there is any chance that support would be added for PHPStan generics (https://phpstan.org/blog/generics-by-examples). They are very useful for getting precise type validation from static analysis, but the PSR-2-R sniffs aren't happy with them.
The following is an example of a doc block for a function that takes a class string and constructor arguments, and outputs an instance of the class.
/** * @template T of object * @param class-string<T> $name The name of the class to construct * @param mixed ...$args The arguments to pass to the constructor * @return T */
And here are the resulting PSR-2-R violations.
>> 35: » ·*·@template·T·of·object
36: » ·*·@param·class-string<T>·$name·The·name·of·the·class·to·construct
37: » ·*·@param·mixed·...$args·The·arguments·to·pass·to·the·constructor
----------------------------------------------------------------------------------------------------------------------------------------
LINE 36: ERROR [ ] Invalid typehint `class-string<T>` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
LINE 36: ERROR [x] Possible doc block error: `class-string<T> $name The name of the class to construct` seems to be missing type
`string`. (Spryker.Commenting.DocBlockParamAllowDefaultValue.Typehint)
LINE 36: ERROR [ ] Invalid typehint `class-string<T>` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
LINE 36: ERROR [ ] Invalid typehint `class-string<T>` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
----------------------------------------------------------------------------------------------------------------------------------------
34: » ·*
35: » ·*·@template·T·of·object
>> 36: » ·*·@param·class-string<T>·$name·The·name·of·the·class·to·construct
37: » ·*·@param·mixed·...$args·The·arguments·to·pass·to·the·constructor
38: » ·*·@return·T
----------------------------------------------------------------------------------------------------------------------------------------
LINE 38: ERROR [ ] Invalid typehint `T` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
LINE 38: ERROR [ ] Invalid typehint `T` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
LINE 38: ERROR [ ] Invalid typehint `T` (PSR2R.Commenting.FullyQualifiedClassNameInDocBlock.ClassNameInvalid)
----------------------------------------------------------------------------------------------------------------------------------------
36: » ·*·@param·class-string<T>·$name·The·name·of·the·class·to·construct
37: » ·*·@param·mixed·...$args·The·arguments·to·pass·to·the·constructor
>> 38: » ·*·@return·T
39: » ·*/
I can certainly just skip these sniffs, but I thought I'd reach out in case there was any interest in supporting this feature. Thanks!
The text was updated successfully, but these errors were encountered:
I was wondering if there is any chance that support would be added for PHPStan generics (https://phpstan.org/blog/generics-by-examples). They are very useful for getting precise type validation from static analysis, but the PSR-2-R sniffs aren't happy with them.
The following is an example of a doc block for a function that takes a class string and constructor arguments, and outputs an instance of the class.
And here are the resulting PSR-2-R violations.
I can certainly just skip these sniffs, but I thought I'd reach out in case there was any interest in supporting this feature. Thanks!
The text was updated successfully, but these errors were encountered: