Skip to content

Commit

Permalink
Fix psalm errors: remove override of template type
Browse files Browse the repository at this point in the history
See doctrine/collections#368 for the same
issue in doctrine/collections which has been fixed there.

The issue happens when using ->contains(). Running psalm emits

  > InvalidArgument - Argument 1 of Doctrine\ORM\PersistentCollection::contains
  > expects
  > TMaybeContained:fn-doctrine\common\collections\readablecollection::contains
  > as mixed, but … provided.

Solution: we should either not define @template TMaybeContained or
re-define the complete psalm docblock from ReadableCollection.

Repairing the docblock necessitates an update to the psalm baseline:
one "known issue" is no longer an issue and thus removed.
  • Loading branch information
tantegerda1 committed Mar 22, 2024
1 parent 5ccbc20 commit c54c557
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 11 deletions.
3 changes: 0 additions & 3 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -462,9 +462,6 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Internal/Hydration/ObjectHydrator.php">
<InvalidArgument>
<code><![CDATA[$element]]></code>
</InvalidArgument>
<PossiblyFalseArgument>
<code><![CDATA[$index]]></code>
</PossiblyFalseArgument>
Expand Down
6 changes: 3 additions & 3 deletions src/LazyCriteriaCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ public function isEmpty()
}

/**
* {@inheritDoc}
*
* Do an optimized search of an element
*
* @template TMaybeContained
* @param mixed $element The element to search for.
*
* @return bool TRUE if the collection contains $element, FALSE otherwise.
*/
public function contains($element)
{
Expand Down
5 changes: 0 additions & 5 deletions src/PersistentCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,6 @@ public function containsKey($key): bool
return parent::containsKey($key);
}

/**
* {@inheritDoc}
*
* @template TMaybeContained
*/
public function contains($element): bool
{
if (! $this->initialized && $this->getMapping()['fetch'] === ClassMetadata::FETCH_EXTRA_LAZY) {
Expand Down

0 comments on commit c54c557

Please sign in to comment.