Skip to content

Commit

Permalink
Add unit tests and restore alias usage
Browse files Browse the repository at this point in the history
  • Loading branch information
CHItA committed Jan 6, 2021
1 parent c8834c9 commit c25eeae
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 106 deletions.
2 changes: 1 addition & 1 deletion src/Parser/DocBlockParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function parse(?string $comment, ParserContext $context): DocBlockNode
$factory = DocBlockFactory::createInstance();
$docBlockContext = new Context(
$context->getNamespace() ?? '',
$context->getImports() ?: []
$context->getAliases() ?: []
);
$docBlock = $factory->create($comment, $docBlockContext);
} catch (\Exception $e) {
Expand Down
4 changes: 1 addition & 3 deletions src/Parser/NodeVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ public function leaveNode(AbstractNode $node)
protected function addAliases(UseNode $node)
{
foreach ($node->uses as $use) {
$alias = $use->alias !== null ? $use->alias->__toString() : null;
$alias = $use->getAlias()->toString();
$fullName = $use->name->__toString();
$this->context->addAlias($alias, $fullName);
$alias = $alias ?? $use->getAlias()->toString();
$this->context->addImport($alias, $fullName);
}
}

Expand Down
11 changes: 0 additions & 11 deletions src/Parser/ParserContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ class ParserContext
/** @var string|null */
protected $namespace;
protected $aliases;
protected $imports = [];
protected $class;
/** @var string|null */
protected $file;
Expand Down Expand Up @@ -76,16 +75,6 @@ public function getAliases()
return $this->aliases;
}

public function addImport(string $alias, string $name): void
{
$this->imports[$alias] = $name;
}

public function getImports()
{
return $this->imports;
}

public function enterFile($file, $hash): void
{
$this->file = $file;
Expand Down
Loading

0 comments on commit c25eeae

Please sign in to comment.