-
Notifications
You must be signed in to change notification settings - Fork 20
Add deprecations errors for functions typehints #15
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
Add deprecations errors for functions typehints #15
Conversation
ee435ce
to
ebf68c2
Compare
I've added closures as discussed here #13 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really good! I've found a few minor issues but otherwise this is great! 👍
return []; | ||
} | ||
|
||
/** @var FunctionReflection $function */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line with @var
does not have to be here if we have that if
right below.
|
||
$errors = []; | ||
foreach ($functionSignature->getParameters() as $i => $parameter) { | ||
/** @var ParameterReflection $parameter */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this @var
has to exist - $functionSignature->getParameters()
is already properly annotated.
private function getClassDeprecationDescription(ClassReflection $class): string | ||
{ | ||
$description = null; | ||
if (method_exists($class, 'getDeprecatedDescription')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're on 0.12 already, this method always exists.
|
||
$errors = []; | ||
foreach ($functionSignature->getParameters() as $i => $parameter) { | ||
/** @var ParameterReflection $parameter */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This @var
does not have to be here.
private function getClassDeprecationDescription(ClassReflection $class): string | ||
{ | ||
$description = null; | ||
if (method_exists($class, 'getDeprecatedDescription')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getDeprecatedDescription
always exists
use PHPStan\Broker\Broker; | ||
use PHPStan\Reflection\ClassReflection; | ||
|
||
trait DeprecationHelper |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really dislike traits. Make this a service that's injected into the constructor instead. Thank you.
@@ -10,4 +10,6 @@ rules: | |||
- PHPStan\Rules\Deprecations\InheritanceOfDeprecatedInterfaceRule | |||
- PHPStan\Rules\Deprecations\InstantiationOfDeprecatedClassRule | |||
- PHPStan\Rules\Deprecations\TypeHintDeprecatedInClassMethodSignatureRule | |||
- PHPStan\Rules\Deprecations\TypeHintDeprecatedInClosureSignatureRule | |||
- PHPStan\Rules\Deprecations\TypeHintDeprecatedInFunctionSignatureRule |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TypeHintDeprecatedInFunctionSignatureRule
should be in different commit.
ebf68c2
to
51e7861
Compare
I updated the branch. I'm sorry ‒ I reorganized things a bit so I had to force-push. |
Perfect, thank you! |
@paxal If you'd be interested, I can always throw more work at you in PHPStan core :) There are many simple bugs that can be fixed if you're willing to dip your toes in the internals :) Since you already know how writing rules work, it should be easy for you to learn a little bit more... If you're interested, I can give you more info on each issue. |
Thank you Ondřej, I bookmarked your link :) |
InFunctionNode