-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Solve some PHPStan baseline errors #10242
Conversation
@@ -675,11 +675,12 @@ public function matching(Criteria $criteria): Collection | |||
/** | |||
* Retrieves the wrapped Collection instance. | |||
* | |||
* @return Collection<TKey, T> | |||
* @return Collection<TKey, T>&Selectable<TKey, T> | |||
*/ | |||
public function unwrap(): 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.
In the matching method, there is the code
public function matching(Criteria $criteria): Collection
{
if ($this->isDirty) {
$this->initialize();
}
if ($this->initialized) {
return $this->unwrap()->matching($criteria);
}
So, unwrap need to return a Selectable if we want to call matching
on it.
@@ -97,7 +97,7 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec | |||
* | |||
* @param EntityManagerInterface $em The EntityManager the collection will be associated with. | |||
* @param ClassMetadata $class The class descriptor of the entity type of this collection. | |||
* @psalm-param Collection<TKey, T> $collection The collection elements. | |||
* @psalm-param Collection<TKey, T>&Selectable<TKey, T> $collection The collection elements. | |||
*/ | |||
public function __construct(EntityManagerInterface $em, $class, Collection $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.
Since unwrap
need to return a Selectable (cf next comment), we need to only accepts selectable.
@@ -419,12 +419,6 @@ public function commit($entity = null) | |||
try { | |||
// Collection deletions (deletions of complete collections) | |||
foreach ($this->collectionDeletions as $collectionToDelete) { | |||
if (! $collectionToDelete instanceof PersistentCollection) { |
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 not possible since collectionDeletions
is always containing PersistentCollection.
- when looking at the added value they are always persistent collection
- it it was possible to go in this if, we would have called
$collectionToDelete->getMapping()
butgetMapping
only exists for PersistentCollection.
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 code was deliberately added in #7861, which is a bit worrying, but also, the test that was added in that PR still passes, so I guess it's fine?
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.
Yes. I would say that the developer wanted to be BC
- If not PersistentCollection do like before
- If PersistentCollection add the bugfix
But it's not possible to have something else than PersistentCollection ^^
(You can look at the place where collectionDeletions
is updated)
@@ -222,14 +222,14 @@ class UnitOfWork implements PropertyChangedListener | |||
/** | |||
* All pending collection deletions. | |||
* | |||
* @psalm-var array<int, Collection<array-key, object>> | |||
* @psalm-var array<int, PersistentCollection<array-key, object>> |
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.
We only add PersistentCollection to this array
if ($orgValue instanceof PersistentCollection) {
// A PersistentCollection was de-referenced, so delete it.
$coid = spl_object_id($orgValue);
if (isset($this->collectionDeletions[$coid])) {
continue;
}
$this->collectionDeletions[$coid] = $orgValue;
$changeSet[$propName] = $orgValue; // Signal changeset, to-many assocs will be ignored.
continue;
}
*/ | ||
private $collectionDeletions = []; | ||
|
||
/** | ||
* All pending collection updates. | ||
* | ||
* @psalm-var array<int, Collection<array-key, object>> | ||
* @psalm-var array<int, PersistentCollection<array-key, object>> |
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.
We only add PersistentCollection to this array
if ($value instanceof PersistentCollection && $value->isDirty()) {
$coid = spl_object_id($value);
$this->collectionUpdates[$coid] = $value;
$this->visitedCollections[$coid] = $value;
}
@@ -238,7 +238,7 @@ class UnitOfWork implements PropertyChangedListener | |||
* At the end of the UnitOfWork all these collections will make new snapshots | |||
* of their data. | |||
* | |||
* @psalm-var array<int, Collection<array-key, object>> | |||
* @psalm-var array<int, PersistentCollection<array-key, object>> |
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.
We only add PersistentCollection to this array
if ($value instanceof PersistentCollection && $value->isDirty()) {
$coid = spl_object_id($value);
$this->collectionUpdates[$coid] = $value;
$this->visitedCollections[$coid] = $value;
}
I just have one error to solve for phpstan https://github.com/doctrine/orm/actions/runs/3509913825/jobs/5879333229 It's related to the code
we're only checking value is an instanceof Collection before passing the value to the PersistentCollection, but as explained in the comment of the PR, Persistent require we pass a Selectable&Collection or the Should I just add this error to the baseline ? (So it would be 5 less, for 1 more in the baseline) |
Yes, it sounds like a fair tradeoff 👍 |
Thanks @VincentLanglet ! |
This is some things I saw in the baseline which could be easily solve I think.