Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion src/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use function class_exists;
use function class_implements;
use function count;
use function current;
use function end;
use function in_array;
use function key;
Expand Down Expand Up @@ -273,6 +274,10 @@ private function parseTypes(ArrayIterator $tokens, Context $context, int $parser
} elseif ($token === self::OPERATOR_ARRAY) {
end($types);
$last = key($types);
if ($last === null) {
throw new InvalidArgumentException('Unexpected array operator');
}

$lastItem = $types[$last];
if ($lastItem instanceof Expression) {
$lastItem = $lastItem->getValueType();
Expand Down Expand Up @@ -317,7 +322,7 @@ private function parseTypes(ArrayIterator $tokens, Context $context, int $parser
);
}
} elseif (count($types) === 1) {
return $types[0];
return current($types);
}

if ($compoundToken === '|') {
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/TypeResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,19 @@ public function testExceptionIsThrownIfTypeIsEmpty(): void
$fixture->resolve(' ', new Context(''));
}

/**
* @uses \phpDocumentor\Reflection\Types\Context
*
* @covers ::__construct
* @covers ::resolve
*/
public function testInvalidArrayOperator(): void
{
$this->expectException('InvalidArgumentException');
$fixture = new TypeResolver();
$fixture->resolve('[]', new Context(''));
}

/**
* Returns a list of keywords and expected classes that are created from them.
*
Expand Down