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 21, 2024
1 parent 5ccbc20 commit 00952f9
Show file tree
Hide file tree
Showing 3 changed files with 1 addition 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
4 changes: 1 addition & 3 deletions src/LazyCriteriaCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,9 @@ public function isEmpty()
}

/**
* {@inheritDoc}
*
* Do an optimized search of an element
*
* @template TMaybeContained
* @return bool TRUE if the collection contains $element, FALSE otherwise.
*/
public function contains($element)

Check failure on line 83 in src/LazyCriteriaCollection.php

View workflow job for this annotation

GitHub Actions / Static Analysis with Psalm

MissingParamType

src/LazyCriteriaCollection.php:83:30: MissingParamType: Parameter $element has no provided type (see https://psalm.dev/154)
{
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 00952f9

Please sign in to comment.