-
Notifications
You must be signed in to change notification settings - Fork 46
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
Require value types for iterables #70
Conversation
Hi, Just ask The main hurdle is that it differentiates between implicit and explicit mixed, but the |
You could also fix the existing rules to register them to |
btw I also tried at #35 but there were some reflection issues... is it fixed now? |
What reflection issues? |
https://travis-ci.org/phpstan/phpstan-strict-rules/jobs/490487289 |
I said that above:
So it's fine for me if the rule currently addreses native typehints without any item specification in the phpDoc. |
@@ -31,7 +34,11 @@ public function processNode(Node $node, Scope $scope): array | |||
throw new \PHPStan\ShouldNotHappenException(); | |||
} | |||
|
|||
$methodReflection = $scope->getClassReflection()->getNativeMethod($node->name->name); | |||
if (!$scope->isInTrait()) { |
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 had to leave this in to get
phpstan-strict-rules/tests/Rules/Methods/MissingMethodReturnTypehintRuleTest.php
Lines 48 to 63 in a1b5b6e
[ | |
'Method MissingMethodReturnTypehint\FooTrait::c1() has no return typehint specified.', | |
42, | |
], | |
[ | |
'Method MissingMethodReturnTypehint\FooTrait::c2() has a return type array with no value type specified.', | |
46, | |
], | |
[ | |
'Method MissingMethodReturnTypehint\FooTrait::c3() has a return type iterable with no value type specified.', | |
50, | |
], | |
[ | |
'Method MissingMethodReturnTypehint\FooTrait::c4() has a return type ArrayObject with no value type specified.', | |
54, | |
], |
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.
Please follow my advice I gave here: #70 (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.
I can't get that to work... I end up with the using class name but the line number from the trait (eg 42: Method MissingMethodReturnTypehint\Foo::c1() has no return typehint specified.
).
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.
Can you push this change as a new commit so I can review it?
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.
Pushed 10eee51.
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.
The results look fine to me, just the declaring class is wrong there - which is something we might fix in PHPStan's core, but it's not a big deal.
@ondrejmirtes Thanks; I've tweaked the tests slightly to remove the override, since it's now testing the class rather than the trait directly. |
@ondrejmirtes Hopefully all done now. |
@ondrejmirtes Is anything needed to merge this PR? |
FYI I plan to move these mixed-detecting rules from strict-rules to phpstan/phpstan as a new level 6 for the new version 0.12 :) Stay tuned! |
I just pushed an implementation of this in Thank you! |
This is a PR to require that the value types of iterables are defined (eg
array<string>
rather than justarray
).I've implemented return types, but will hold for feedback. The only concern I can see is that it's not possible to allow defining
@return array<mixed>
(which is defining a value type; can't see how to reliably distinguish between implicit and explicit use ofmixed
).(Refs libero/php-coding-standard#40.)