diff --git a/composer.json b/composer.json index 7b70fe8..19114c2 100644 --- a/composer.json +++ b/composer.json @@ -18,7 +18,7 @@ "php": "^8.0", "ext-tokenizer": "*", "league/pipeline": "^1.0.0", - "nikic/php-parser": "^4.11.0", + "nikic/php-parser": "4.11.0", "phpdocumentor/reflection-docblock": "^5.2", "phpdocumentor/type-resolver": "^1.4", "symfony/console": "^5.3.2", diff --git a/src/Code/UseStatements.php b/src/Code/UseStatements.php index 4bfd394..039fa86 100644 --- a/src/Code/UseStatements.php +++ b/src/Code/UseStatements.php @@ -27,6 +27,6 @@ public function fullyQualifiedNameFor(Name $name): string return $useStatement->fullyQualifiedName($name); } } - return (string) $name; + return $name->fullName(); } } diff --git a/src/Code/Variables/TypeDeclaration.php b/src/Code/Variables/TypeDeclaration.php index 4c90f3b..2997a5a 100644 --- a/src/Code/Variables/TypeDeclaration.php +++ b/src/Code/Variables/TypeDeclaration.php @@ -71,7 +71,7 @@ public function references(): array return [$this->isArray() ? new Name($this->removeArraySuffix()) : $this->names[0]]; } - $typesFromUnion = array_map(static fn (Name $name) => TypeDeclaration::from((string) $name), $this->names); + $typesFromUnion = array_map(static fn (Name $name) => TypeDeclaration::from($name->fullName()), $this->names); $references = array_filter($typesFromUnion, static fn (TypeDeclaration $type) => ! $type->isBuiltIn()); return array_map( diff --git a/tests/unit/Code/UseStatementsTest.php b/tests/unit/Code/UseStatementsTest.php index 4451b9d..2452551 100644 --- a/tests/unit/Code/UseStatementsTest.php +++ b/tests/unit/Code/UseStatementsTest.php @@ -24,4 +24,14 @@ function it_gets_fully_qualified_name_from_alias() $this->assertEquals('Package\\SubPackage\\AnotherClass', $fullyQualifiedName); } + + /** @test */ + function it_get_fully_qualified_name_if_not_imported() + { + $useStatements = new UseStatements([]); + $fqn = 'Inline\\Fully\\Qualified\\Name'; + $name = new Name($fqn); + + $this->assertEquals($fqn, $useStatements->fullyQualifiedNameFor($name)); + } } diff --git a/tests/unit/Code/Variables/TypeDeclarationTest.php b/tests/unit/Code/Variables/TypeDeclarationTest.php index 435dd3d..3678ac0 100644 --- a/tests/unit/Code/Variables/TypeDeclarationTest.php +++ b/tests/unit/Code/Variables/TypeDeclarationTest.php @@ -104,13 +104,22 @@ function it_represents_to_string_union_types() /** @test */ function it_extracts_reference_types_from_union_types() { - $unionType = TypeDeclaration::fromUnionType(['string', 'AClass', 'null', 'AnotherClass[]']); + $unionType = TypeDeclaration::fromUnionType( + [ + 'string', + 'AClass', + 'null', + 'AnotherClass[]', + 'Class\\With\\Namespace', + ] + ); $references = $unionType->references(); - $this->assertCount(2, $references); + $this->assertCount(3, $references); $this->assertEquals('AClass', (string) $references[1]); $this->assertEquals('AnotherClass', (string) $references[3]); + $this->assertEquals('Class\\With\\Namespace', $references[4]->fullName()); } /** @test */