Skip to content

Commit

Permalink
Merge pull request #19 from Amegatron/5.0
Browse files Browse the repository at this point in the history
Fix lost FQN in TypeDeclaration::references()
  • Loading branch information
MontealegreLuis authored Nov 16, 2021
2 parents 68212e9 + b04dd5c commit 1416ae2
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Code/UseStatements.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public function fullyQualifiedNameFor(Name $name): string
return $useStatement->fullyQualifiedName($name);
}
}
return (string) $name;
return $name->fullName();
}
}
2 changes: 1 addition & 1 deletion src/Code/Variables/TypeDeclaration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/Code/UseStatementsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
13 changes: 11 additions & 2 deletions tests/unit/Code/Variables/TypeDeclarationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 1416ae2

Please sign in to comment.