Skip to content

Commit 937a026

Browse files
committed
fix "RuntimeException" for "array-key" and for "class-string"
1 parent 4fc5976 commit 937a026

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

src/TypeResolver.php

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ArrayIterator;
1717
use InvalidArgumentException;
1818
use phpDocumentor\Reflection\Types\Array_;
19+
use phpDocumentor\Reflection\Types\ArrayKey;
1920
use phpDocumentor\Reflection\Types\ClassString;
2021
use phpDocumentor\Reflection\Types\Collection;
2122
use phpDocumentor\Reflection\Types\Compound;
@@ -544,6 +545,7 @@ private function resolveCollection(ArrayIterator $tokens, Type $classType, Conte
544545
// check the key type for an "array" collection. We allow only
545546
// strings or integers.
546547
if (
548+
!$keyType instanceof ArrayKey &&
547549
!$keyType instanceof String_ &&
548550
!$keyType instanceof Integer &&
549551
!$keyType instanceof Compound
@@ -556,6 +558,7 @@ private function resolveCollection(ArrayIterator $tokens, Type $classType, Conte
556558
if ($keyType instanceof Compound) {
557559
foreach ($keyType->getIterator() as $item) {
558560
if (
561+
!$item instanceof ArrayKey &&
559562
!$item instanceof String_ &&
560563
!$item instanceof Integer
561564
) {

src/Types/ClassString.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@
1414
namespace phpDocumentor\Reflection\Types;
1515

1616
use phpDocumentor\Reflection\Fqsen;
17-
use phpDocumentor\Reflection\Type;
1817

1918
/**
2019
* Value Object representing the type 'string'.
2120
*
2221
* @psalm-immutable
2322
*/
24-
final class ClassString implements Type
23+
final class ClassString extends String_
2524
{
2625
/** @var Fqsen|null */
2726
private $fqsen;

tests/unit/CollectionResolverTest.php

+13
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,19 @@ public function testBadArrayCollectionKey(): void
223223
$fixture->resolve('array<object,string>', new Context(''));
224224
}
225225

226+
/**
227+
* @covers ::__construct
228+
* @covers ::resolve
229+
*/
230+
public function testGoodArrayCollectionKey(): void
231+
{
232+
$fixture = new TypeResolver();
233+
$fixture->resolve('array<array-key,string>', new Context(''));
234+
235+
$fixture = new TypeResolver();
236+
$fixture->resolve('array<class-string,string>', new Context(''));
237+
}
238+
226239
/**
227240
* @covers ::__construct
228241
* @covers ::resolve

0 commit comments

Comments
 (0)