Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions src/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -643,18 +643,42 @@
return new Array_(...$types);
}

if ($types[1] instanceof Compound && $types[1]->getIterator()->count() === 2) {
if ($this->validArrayKeyType($types[1]->get(0)) && $this->validArrayKeyType($types[1]->get(1))) {
return new Array_(...$types);
}
if ($types[1] instanceof Compound) {
for ($i = 0; $i < $types[1]->getIterator()->count(); $i++) {
if ($this->validArrayKeyType($types[1]->get($i))) {
continue;
}

throw new RuntimeException('An array can have only integers or strings as keys');
}

return new Array_(...$types);
}

throw new RuntimeException('An array can have only integers or strings as keys');
}

private function validArrayKeyType(?Type $type): bool
{
return $type instanceof String_ || $type instanceof Integer;
return $type instanceof String_ ||
$type instanceof CallableString ||

Check failure on line 664 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Instanceof between phpDocumentor\Reflection\Type|null and phpDocumentor\Reflection\PseudoTypes\CallableString will always evaluate to false.
$type instanceof HtmlEscapedString ||

Check failure on line 665 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Instanceof between phpDocumentor\Reflection\Type|null and phpDocumentor\Reflection\PseudoTypes\HtmlEscapedString will always evaluate to false.
$type instanceof IntegerRange ||
$type instanceof IntegerValue ||
$type instanceof IntMask ||
$type instanceof IntMaskOf ||
$type instanceof KeyOf ||
$type instanceof LiteralString ||

Check failure on line 671 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Instanceof between phpDocumentor\Reflection\Type|null and phpDocumentor\Reflection\PseudoTypes\LiteralString will always evaluate to false.
$type instanceof LowercaseString ||

Check failure on line 672 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Instanceof between phpDocumentor\Reflection\Type|null and phpDocumentor\Reflection\PseudoTypes\LowercaseString will always evaluate to false.
$type instanceof NegativeInteger ||
$type instanceof NonEmptyLowercaseString ||

Check failure on line 674 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Instanceof between phpDocumentor\Reflection\Type|null and phpDocumentor\Reflection\PseudoTypes\NonEmptyLowercaseString will always evaluate to false.
$type instanceof NonEmptyString ||

Check failure on line 675 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Instanceof between phpDocumentor\Reflection\Type|null and phpDocumentor\Reflection\PseudoTypes\NonEmptyString will always evaluate to false.
$type instanceof PositiveInteger ||
$type instanceof StringValue ||
$type instanceof ClassString ||

Check failure on line 678 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Instanceof between phpDocumentor\Reflection\Type|null and phpDocumentor\Reflection\Types\ClassString will always evaluate to false.
$type instanceof InterfaceString ||
$type instanceof TraitString ||

Check failure on line 680 in src/TypeResolver.php

View workflow job for this annotation

GitHub Actions / Static analysis / Static Code Analysis (8.0)

Instanceof between phpDocumentor\Reflection\Type|null and phpDocumentor\Reflection\PseudoTypes\TraitString will always evaluate to false.
$type instanceof Integer;
Comment on lines +663 to +681
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to include all of this, the string and integer type variants are extending the String_ or Integer class. The actual problem you solved is in the way you handle the compound type.

}

private function parse(TokenIterator $tokenIterator): TypeNode
Expand Down
Loading