-
-
Notifications
You must be signed in to change notification settings - Fork 505
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 PHPStan check for iterable types #2437
Conversation
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'm not saying "definitely no", but given few definitions are off and tests are green I'm not sure these changes provide any real value other than satisfying SA tools. Maybe we could stay with level 5 for tests and improve just the main codebase for higher levels? To add another pro some time ago while working on sanity checks I needed to ignore phpstan/psalm errors in tests because I wanted to pass wrong values to check if exceptions are raised properly.
tests/Doctrine/ODM/MongoDB/Tests/Aggregation/AggregationOperatorsProviderTrait.php
Show resolved
Hide resolved
@@ -64,6 +64,8 @@ public function provideAccumulators(): array | |||
} | |||
|
|||
/** | |||
* @param mixed[] $args |
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.
FWIW I'm not really a fan of adding mixed[]
all over the place, IMO this is bringing little to no value
@@ -225,6 +225,9 @@ class MyEventListener | |||
/** @psalm-var array<string, list<class-string>> */ | |||
public $called = []; | |||
|
|||
/** | |||
* @param mixed[] $args |
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 we somehow note that first element should be an instance of LifecycleEventArgs
(and we don't care about the rest)?
@@ -162,6 +162,9 @@ public function getSubscribedEvents(): array | |||
]; | |||
} | |||
|
|||
/** | |||
* @param mixed[] $args |
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.
Same question as before with LifecycleEventArgs
@@ -43,6 +43,8 @@ public function testHintIsNotSetByDefault(): void | |||
} | |||
|
|||
/** | |||
* @param array<array<string, string>> $tags |
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.
Shall we introduce a ReadPreferenceTagsShape
shape similar to SortShape
?
@@ -114,6 +117,9 @@ public function getSubscribedEvents(): array | |||
return $this->events; | |||
} | |||
|
|||
/** | |||
* @param mixed[] $args |
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.
Here goes LifecycleEventArgs
question again
@@ -63,6 +63,9 @@ class MODM83EventListener | |||
/** @var array<string, class-string[]> */ | |||
public $called = []; | |||
|
|||
/** | |||
* @param mixed[] $args |
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'm just marking all places with LifecycleEventArgs
I see in case there'd be a place to improve (next 2 classes could use this as well)
@@ -78,7 +78,7 @@ public function __construct() | |||
* by mapping array indexes (size URL's are required, cropMetadata is not). | |||
* Any invalid elements will be ignored. | |||
* | |||
* @param array|Traversable $embeddedDocuments | |||
* @param array<MODM95TestEmbeddedDocument>|Traversable<MODM95TestEmbeddedDocument> $embeddedDocuments |
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.
Both @param
and code could be improved to use iterable<MODM95TestEmbeddedDocument>
which wasn't available at the time of writing the test
@@ -229,6 +231,10 @@ public function getDocumentsAndExpectedData(): array | |||
]; | |||
} | |||
|
|||
/** | |||
* @param array<string, mixed> $expectedData | |||
* @param array<string, mixed>|null $preparedData |
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 doubt that null
should be allowed for $preparedData
as the very first thing we do is iterate over it :)
@@ -249,6 +249,9 @@ public function testComputingChangesetForFileWithoutMetadataThrowsNoError(): voi | |||
} | |||
|
|||
/** | |||
* @param array<string, string>|null $origData | |||
* @param array<string, string>|null $updateData |
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.
There are currently also ints and bools in the array
c532cf0
to
d6a5fa1
Compare
7763fc5
to
a035a32
Compare
Thanks @malarzm for the review! I've finally found some time to take a look at this again. I've just updated the code with the comments and make it green improving a bit some of the I'll try to add another commit removing some of the phpdoc that don't add value and adding them to the baseline. |
d4679c9
to
4c337ea
Compare
Awesome! Let me know if you'd need anything :) |
4c337ea
to
babf193
Compare
I think it's ready to review, I understand the |
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.
Thank you very much @franmomu for your hard work on this 🍻
@@ -224,6 +225,9 @@ class MyEventListener | |||
/** @psalm-var array<string, list<class-string>> */ | |||
public array $called = []; | |||
|
|||
/** | |||
* @param array{LifecycleEventArgs} $args |
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.
Cool this was possible :)
Summary
Last PR to add the PHPStan check for iterable types, the remaining ones where the ones in
tests
.