-
-
Notifications
You must be signed in to change notification settings - Fork 506
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
Make PersistentCollectionInterface
and PersistentCollection
generic
#2324
Make PersistentCollectionInterface
and PersistentCollection
generic
#2324
Conversation
@@ -99,7 +100,6 @@ | |||
* isOwningSide: bool, | |||
* isInverseSide: bool, | |||
* strategy?: string, | |||
* notSaved?: bool, |
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.
It is duplicated
@@ -85,7 +85,8 @@ | |||
* version?: bool, | |||
* lock?: bool, | |||
* inherited?: string, | |||
* declared?: class-string | |||
* declared?: class-string, | |||
* prime?: list<string> |
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.
Missing one, I used list<string>
because of:
mongodb-odm/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
Lines 494 to 497 in f033c43
foreach ($reference->{'prime'}->{'field'} as $field) { | |
$attr = $field->attributes(); | |
$mapping['prime'][] = (string) $attr['name']; | |
} |
* | ||
* @return bool | ||
* @return bool|T|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.
Here we can return the result of $removed = $this->coll->remove($offset);
which is T|null
@@ -268,3 +268,33 @@ parameters: | |||
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'DateTime' and null will always evaluate to false\\.$#" | |||
count: 1 | |||
path: tests/Doctrine/ODM/MongoDB/Tests/Types/DateTypeTest.php | |||
|
|||
# import type in PHPStan does not work, see https://github.com/phpstan/phpstan/issues/5091 |
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.
All these issues being ignored are because in PHPStan, apparently importing type aliases from a trait does not work: phpstan/phpstan#5091
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.
Subscribed to that issue 👍
$unserialized->setOwner($owner, [ | ||
'type' => ClassMetadata::ONE, | ||
'name' => 'name', | ||
'fieldName' => 'fieldName', | ||
'isCascadeRemove' => false, | ||
'isCascadePersist' => false, | ||
'isCascadeRefresh' => false, | ||
'isCascadeMerge' => false, | ||
'isCascadeDetach' => false, | ||
'isOwningSide' => false, | ||
'isInverseSide' => false, | ||
'targetDocument' => stdClass::class, | ||
]); |
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 to create a valid FieldMapping
.
$pcoll = new PersistentCollection($collection, $this->dm, $this->uow); | ||
$this->assertSame(2, $pcoll[0]); |
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.
These changes in tests are because PersistentCollection
is not supposed to be handling scalars.
*/ | ||
private $snapshot = []; | ||
|
||
/** | ||
* Collection's owning entity | ||
* | ||
* @var object|null | ||
* @psalm-var T|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.
This one seems off: the owner can be (and usual is) of other type than what's inside of the collection
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.
Oops, you are right, changing it.
@@ -268,3 +268,33 @@ parameters: | |||
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\) with 'DateTime' and null will always evaluate to false\\.$#" | |||
count: 1 | |||
path: tests/Doctrine/ODM/MongoDB/Tests/Types/DateTypeTest.php | |||
|
|||
# import type in PHPStan does not work, see https://github.com/phpstan/phpstan/issues/5091 |
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.
Subscribed to that issue 👍
eec7e12
to
d8523ac
Compare
d8523ac
to
5e57d0e
Compare
Thanks @franmomu! |
Summary
Adding more generics, in this case to
PersistentCollectionInterface
andPersistentCollection
. While adding these changes, other problems arose, I'll add comments to the code so it's easier to review.