Skip to content

Commit f61b896

Browse files
committed
TASK: Remove @phpstan-ignore-next-line by asserting that an array is indeed associative (0 cost in production)
Sadly we cant annotate the param in the constructor to tell psalm, that we only want to accept string keys. At least i have found no way
1 parent 0adb4c0 commit f61b896

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

src/TypeSystem/Inferrer/InferredTypes.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class InferredTypes
3535
private function __construct(
3636
TypeInterface ...$types
3737
) {
38-
// @phpstan-ignore-next-line
38+
assert(self::isAssociativeArray($types), '$types must be an associative array');
3939
$this->types = $types;
4040
}
4141

@@ -53,4 +53,20 @@ public function getType(string $identifierName): ?TypeInterface
5353
{
5454
return $this->types[$identifierName] ?? null;
5555
}
56+
57+
/**
58+
* @template T
59+
* @param array<string|int,T> $array
60+
* @phpstan-assert-if-true array<string,T> $array
61+
*/
62+
private static function isAssociativeArray(array $array): bool
63+
{
64+
foreach ($array as $key => $value) {
65+
if (is_string($key)) {
66+
continue;
67+
}
68+
return false;
69+
}
70+
return true;
71+
}
5672
}

0 commit comments

Comments
 (0)