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
@param type can be omitted #77
Comments
This is actually a complaint in Psalm. It's due to a bug where Psalm doesn't even comprehend the line is a parameter tag when the type is missing (It shows when you ask Psalm to fix the code, it won't add the type, it will add an entire new @param line) It was suggested that Psalm should emit an issue when encountering this syntax. The case where the type is in signature and we don't want to repeat it but we still want to add documentation is interesting though. Not sure what we want to make of that |
When you don't have the type in
No, PHPStan detects such situation. I don't think it's useful to allow this, it's rightfully considered a PHPDoc syntax error. |
One more point to consider is that people can use |
wouldn't this be reported as an out-of-sync type then ? |
Yeah, if you have for example native typehint |
It isn't because I understand that it's worthless for a tool like PHPStan, but PHPStan is not the only tool parsing
Note that the type is optional here. Since there is no real standard about PHPDoc annotations, I would consider phpDocumentor's documentation to be the de-facto standard at the moment. The error message currently produced by PHPStan tells me that the standard is not implemented correctly.
That I can agree on. I would totally understand, if PHPStan errors on
And that's exactly the kind of redundancy we'd like to eliminate. SuggestionPasses without an error: /**
* @param $i Some documentation
*/
function takesAnInt(int $i): void {
} Errors because of missing type information for /**
* @param $i Some documentation
*/
function takesAnInt($i): void {
} Errors because of useless /**
* @param $i
*/
function takesAnInt(int $i): void {
} Errors because of useless /**
* @param $i
*/
function takesAnInt($i): void {
} What do you think? |
Yeah, it shouldn't be that hard to support this if that's what people want. We don't need the Only thing that should remain parse error should be
I hope the parser here can be modified to support this. |
Note, at some point PHPDoc allowed for
Which is IIRC reported / fixed by CS Fixer (or some other tool?) This means stuff like Symfony's https://github.com/symfony/symfony/blob/08fa74a16c84895575e305b2a7ee3a03e371f79b/src/Symfony/Component/Console/Command/Command.php#L448 will get misinterpreted by tools which understand / support both, like PHPStorm and possibly others (PHPStorm thinks the linked param's type is |
You can now enjoy this in: https://github.com/phpstan/phpstan/releases/tag/1.7.12 |
@ondrejmirtes can this change be configured?
before 1.7.12 it was reported as error:
and since 1.7.12, its not. This is a pain, as I would love phpstan to continue to report this issue (I want to have types declared here :). |
@tmotyl PHPStan still complains about the parameters not having a documented type: https://phpstan.org/r/c5b0d29b-c9a3-46d5-bd9a-abec237715ed |
@derrabus I see where the issue is -> My project is on phpstan level 2, which is now not reporting the issue. |
Sounds like a case of https://xkcd.com/1172/. 😅 |
I don't understand why people complain that an issue that THEY STILL IGNORED is stopped being reported, sounds like a win in my book :) I consider the removed issue kind of a duplicate of the "missing typehint" errors from level 6 so this is the right behaviour going forward. |
@ondrejmirtes now that I know that it will be eventually reported (but on higher level) it's ok. |
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. |
According to https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/param.html, the type may be omitted. This is especially useful in PHP 8 applications, which can almost fully typehint all arguments. The type in the PHPdoc in this case is redundant and may only lead to out-of-sync types.
PHPstorm and Psalm already appear to support this. However, this is not yet the case with PHPstan: https://phpstan.org/r/691a2424-e087-45a0-a9ce-774a57f887ec
(fyi, we're about to remove the types in Symfony, which is why I checked support in the popular static analysis libraries)
The text was updated successfully, but these errors were encountered: