-
-
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
Use typed properties #2473
Use typed properties #2473
Conversation
31c2d43
to
42a2059
Compare
42a2059
to
b4799a3
Compare
* @var array<string, mixed>|mixed | ||
*/ | ||
private $query = []; |
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 may not be an array but the actual value (when calling equals()
without setting the fieldName
. Reported by \Doctrine\ODM\MongoDB\Tests\Query\ExprTest::testOperatorWithoutCurrentFieldWrapsEqualityCriteria()
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.
Halfway through 🙈
@@ -12,7 +12,7 @@ | |||
class Bucket extends AbstractBucket | |||
{ | |||
/** @var mixed[] */ | |||
private $boundaries; | |||
private ?array $boundaries = null; |
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.
Why nullable? PHPDoc says it's an array
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.
Ah I guess it's because of null checks later. Maybe we should keep this typed as array and use isset
later? On the other hand this would change how $fields = ['boundaries' => $this->boundaries];
would be behaving when no boundaries were set so maybe null
is a good choice 🤔
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 fixed that by making the property private array $boundaries
and using null coalesce operator below: $this->boundaries ?? null
to keep the result same as before. Looks much cleaner now but Psalm complains about it.
I fixed the issues mentioned above. I think we need to change some phpstan rules to allow these changes if we want to avoid nullable properties. |
tests/Doctrine/ODM/MongoDB/Tests/Functional/CustomCollectionsTest.php
Outdated
Show resolved
Hide resolved
I haven't thought of any way to fix SA so I think that nullable optional properties will be the way to go after all. Sorry for wrong advice there 🙈 |
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 think we can ignore the RedundantPropertyInitializationCheck
psalm issues for now
Summary
Makes use of PHP 7.4 typed properties where applicable. Most of it was handled by Rector 🚀 and then manually fixed up.
Additionally, I removed some invalid
@doesNotPerformAssertions
annotations on the tests that actually perform them. AddingfailOnRisky="true"
inphpunit.xml.dist
marks them as failed so it won't happen in the future.Linked issue #2464
While all tests are passing at the moment, it would be great if someone could help testing it in a real-life application to eliminate potential BC breaks.