Skip to content
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

Merged
merged 5 commits into from
Nov 2, 2022
Merged

Use typed properties #2473

merged 5 commits into from
Nov 2, 2022

Conversation

IonBazan
Copy link
Member

@IonBazan IonBazan commented Oct 4, 2022

Q A
Type improvement
BC Break yes (kind of)
Fixed issues -

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. Adding failOnRisky="true" in phpunit.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.

Comment on lines +43 to 45
* @var array<string, mixed>|mixed
*/
private $query = [];
Copy link
Member Author

@IonBazan IonBazan Oct 4, 2022

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()

Copy link
Member

@malarzm malarzm left a 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;
Copy link
Member

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

Copy link
Member

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 🤔

Copy link
Member Author

@IonBazan IonBazan Oct 6, 2022

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.

lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Facet.php Outdated Show resolved Hide resolved
lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Out.php Outdated Show resolved Hide resolved
lib/Doctrine/ODM/MongoDB/DocumentManager.php Show resolved Hide resolved
lib/Doctrine/ODM/MongoDB/Iterator/CachingIterator.php Outdated Show resolved Hide resolved
lib/Doctrine/ODM/MongoDB/Iterator/UnrewindableIterator.php Outdated Show resolved Hide resolved
@IonBazan
Copy link
Member Author

IonBazan commented Oct 6, 2022

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.

@IonBazan IonBazan requested a review from malarzm October 10, 2022 06:45
@malarzm
Copy link
Member

malarzm commented Oct 22, 2022

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 🙈

Copy link
Contributor

@franmomu franmomu left a 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

@IonBazan IonBazan requested review from franmomu and malarzm November 1, 2022 22:03
@IonBazan IonBazan merged commit 5987555 into doctrine:2.5.x Nov 2, 2022
@IonBazan IonBazan deleted the feature/php-7.4 branch November 2, 2022 10:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants