Skip to content

Commit

Permalink
Merge pull request #7311 from orklah/inArrayAssertionOnTemplate
Browse files Browse the repository at this point in the history
don't crash when pushing a template to in_array
  • Loading branch information
orklah committed Jan 5, 2022
2 parents e41fc67 + a6a0769 commit 3dbc039
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Expand Up @@ -3556,7 +3556,7 @@ private static function getInarrayAssertions(
// - The array may have one of the types but not the others.
//
// NOTE: the negation of the negation is the original assertion.
if ($value_type->getId() !== '' && !$value_type->isMixed()) {
if ($value_type->getId() !== '' && !$value_type->isMixed() && !$value_type->hasTemplate()) {
$assertions[] = 'in-array-' . $value_type->getId();
}
} else {
Expand Down
23 changes: 23 additions & 0 deletions tests/AssertAnnotationTest.php
Expand Up @@ -1898,6 +1898,29 @@ function assertBarNotNull(Foo $foo): bool
function requiresString(string $_str): void {}
',
],
'assertInArrayWithTemplateDontCrash' => [
'<?php
class A{
/**
* @template T
* @param array<T> $objects
* @return array<T>
*/
private function uniquateObjects(array $objects) : array
{
$uniqueObjects = [];
foreach ($objects as $object) {
if (in_array($object, $uniqueObjects, true)) {
continue;
}
$uniqueObjects[] = $object;
}
return $uniqueObjects;
}
}
',
],
'assertionOnMagicProperty' => [
'<?php
/**
Expand Down

0 comments on commit 3dbc039

Please sign in to comment.