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
2 changes: 1 addition & 1 deletion .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
all-build-${{ hashFiles('**/composer.lock') }}
all-build-
- name: Code style check
uses: phpDocumentor/coding-standard@v1.0.0
uses: phpDocumentor/coding-standard@master
with:
args: -s

Expand Down
6 changes: 4 additions & 2 deletions src/TypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
use phpDocumentor\Reflection\Types\Object_;
use phpDocumentor\Reflection\Types\String_;
use RuntimeException;
use const PREG_SPLIT_DELIM_CAPTURE;
use const PREG_SPLIT_NO_EMPTY;
use function array_keys;
use function array_pop;
use function class_exists;
Expand All @@ -40,6 +38,8 @@
use function strtolower;
use function substr;
use function trim;
use const PREG_SPLIT_DELIM_CAPTURE;
use const PREG_SPLIT_NO_EMPTY;

final class TypeResolver
{
Expand Down Expand Up @@ -295,6 +295,7 @@ private function resolveSingleType(string $type, Context $context)
return $this->resolveTypedObject($type);
case $this->isPartialStructuralElementName($type):
return $this->resolveTypedObject($type, $context);

// @codeCoverageIgnoreStart
default:
// I haven't got the foggiest how the logic would come here but added this as a defense.
Expand Down Expand Up @@ -381,6 +382,7 @@ private function resolveTypedArray(string $type, Context $context) : Array_
private function resolveKeyword(string $type) : Type
{
$className = $this->keywords[strtolower($type)];

return new $className();
}

Expand Down
19 changes: 12 additions & 7 deletions src/Types/ContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
use Reflector;
use RuntimeException;
use UnexpectedValueException;
use function array_merge;
use function file_exists;
use function file_get_contents;
use function get_class;
use function is_string;
use function token_get_all;
use function trim;
use const T_AS;
use const T_CLASS;
use const T_CURLY_OPEN;
Expand All @@ -31,13 +38,6 @@
use const T_NS_SEPARATOR;
use const T_STRING;
use const T_USE;
use function array_merge;
use function file_exists;
use function file_get_contents;
use function get_class;
use function is_string;
use function token_get_all;
use function trim;

/**
* Convenience class to create a Context for DocBlocks when not using the Reflection Component of phpDocumentor.
Expand Down Expand Up @@ -172,11 +172,13 @@ public function createForNamespace(string $namespace, string $fileContents) : Co

$tokens->next();
}

break;
case T_USE:
if ($currentNamespace === $namespace) {
$useStatements = array_merge($useStatements, $this->parseUseStatement($tokens));
}

break;
}

Expand Down Expand Up @@ -282,6 +284,7 @@ private function extractUseStatements(ArrayIterator $tokens) : array
default:
break;
}

break;
case 'start-alias':
switch ($tokenId) {
Expand All @@ -295,6 +298,7 @@ private function extractUseStatements(ArrayIterator $tokens) : array
default:
break;
}

break;
case 'grouped':
switch ($tokenId) {
Expand All @@ -318,6 +322,7 @@ private function extractUseStatements(ArrayIterator $tokens) : array
default:
break;
}

break;
case 'grouped-alias':
switch ($tokenId) {
Expand Down
25 changes: 0 additions & 25 deletions tests/unit/CollectionResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@

use phpDocumentor\Reflection\Types\Array_;
use phpDocumentor\Reflection\Types\Collection;
use phpDocumentor\Reflection\Types\Compound;
use phpDocumentor\Reflection\Types\Context;
use phpDocumentor\Reflection\Types\Object_;
use phpDocumentor\Reflection\Types\String_;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -40,18 +37,15 @@ public function testResolvingCollection() : void
{
$fixture = new TypeResolver();

/** @var Collection $resolvedType */
$resolvedType = $fixture->resolve('ArrayObject<string>', new Context(''));

$this->assertInstanceOf(Collection::class, $resolvedType);
$this->assertSame('\\ArrayObject<string>', (string) $resolvedType);

$this->assertEquals('\\ArrayObject', (string) $resolvedType->getFqsen());

/** @var String_ $valueType */
$valueType = $resolvedType->getValueType();

/** @var Compound $keyType */
$keyType = $resolvedType->getKeyType();

$this->assertInstanceOf(Types\String_::class, $valueType);
Expand All @@ -71,18 +65,15 @@ public function testResolvingCollectionWithKeyType() : void
{
$fixture = new TypeResolver();

/** @var Collection $resolvedType */
$resolvedType = $fixture->resolve('ArrayObject<string[],Iterator>', new Context(''));

$this->assertInstanceOf(Collection::class, $resolvedType);
$this->assertSame('\\ArrayObject<string[],\\Iterator>', (string) $resolvedType);

$this->assertEquals('\\ArrayObject', (string) $resolvedType->getFqsen());

/** @var Object_ $valueType */
$valueType = $resolvedType->getValueType();

/** @var Array_ $keyType */
$keyType = $resolvedType->getKeyType();

$this->assertInstanceOf(Types\Object_::class, $valueType);
Expand All @@ -104,16 +95,13 @@ public function testResolvingArrayCollection() : void
{
$fixture = new TypeResolver();

/** @var Collection $resolvedType */
$resolvedType = $fixture->resolve('array<string>', new Context(''));

$this->assertInstanceOf(Array_::class, $resolvedType);
$this->assertSame('string[]', (string) $resolvedType);

/** @var Array_ $valueType */
$valueType = $resolvedType->getValueType();

/** @var Compound $keyType */
$keyType = $resolvedType->getKeyType();

$this->assertInstanceOf(Types\String_::class, $valueType);
Expand All @@ -133,16 +121,13 @@ public function testResolvingArrayCollectionWithKey() : void
{
$fixture = new TypeResolver();

/** @var Collection $resolvedType */
$resolvedType = $fixture->resolve('array<string,object|array>', new Context(''));

$this->assertInstanceOf(Array_::class, $resolvedType);
$this->assertSame('array<string,object|array>', (string) $resolvedType);

/** @var Array_ $valueType */
$valueType = $resolvedType->getValueType();

/** @var Compound $keyType */
$keyType = $resolvedType->getKeyType();

$this->assertInstanceOf(Types\String_::class, $keyType);
Expand All @@ -162,16 +147,13 @@ public function testResolvingArrayCollectionWithKeyAndWhitespace() : void
{
$fixture = new TypeResolver();

/** @var Collection $resolvedType */
$resolvedType = $fixture->resolve('array<string, object|array>', new Context(''));

$this->assertInstanceOf(Array_::class, $resolvedType);
$this->assertSame('array<string,object|array>', (string) $resolvedType);

/** @var Array_ $valueType */
$valueType = $resolvedType->getValueType();

/** @var Compound $keyType */
$keyType = $resolvedType->getKeyType();

$this->assertInstanceOf(Types\String_::class, $keyType);
Expand Down Expand Up @@ -208,24 +190,20 @@ public function testResolvingCollectionOfCollection() : void
{
$fixture = new TypeResolver();

/** @var Collection $resolvedType */
$resolvedType = $fixture->resolve('ArrayObject<string|integer|double,ArrayObject<DateTime>>', new Context(''));

$this->assertInstanceOf(Collection::class, $resolvedType);
$this->assertSame('\\ArrayObject<string|int|float,\\ArrayObject<\\DateTime>>', (string) $resolvedType);

$this->assertEquals('\\ArrayObject', (string) $resolvedType->getFqsen());

/** @var Collection $valueType */
$valueType = $resolvedType->getValueType();
/** @var Object_ $collectionValueType */
$collectionValueType = $valueType->getValueType();
$this->assertInstanceOf(Types\Collection::class, $valueType);
$this->assertInstanceOf(Types\Object_::class, $valueType->getValueType());
$this->assertEquals('\\ArrayObject', (string) $valueType->getFqsen());
$this->assertEquals('\\DateTime', (string) $collectionValueType->getFqsen());

/** @var Compound $keyType */
$keyType = $resolvedType->getKeyType();
$this->assertInstanceOf(Types\Compound::class, $keyType);
$this->assertInstanceOf(Types\String_::class, $keyType->get(0));
Expand Down Expand Up @@ -294,16 +272,13 @@ public function testResolvingCollectionAsArray() : void
{
$fixture = new TypeResolver();

/** @var Collection $resolvedType */
$resolvedType = $fixture->resolve('array<string,float>', new Context(''));

$this->assertInstanceOf(Array_::class, $resolvedType);
$this->assertSame('array<string,float>', (string) $resolvedType);

/** @var Array_ $valueType */
$valueType = $resolvedType->getValueType();

/** @var Compound $keyType */
$keyType = $resolvedType->getKeyType();

$this->assertInstanceOf(Types\Float_::class, $valueType);
Expand Down
Loading