Skip to content

Commit

Permalink
Parsing aliases in docblocks also
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroMinoccheri authored Jan 3, 2023
1 parent 0487b72 commit 621cc7d
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Analyzer/NameResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function enterNode(Node $node)
break;
}

if (null === $node->type) {
if (!($node->type instanceof FullyQualified)) {
foreach ($phpDocNode->getTags() as $tagValue) {
if ('@' === $tagValue->name[0] && false === strpos($tagValue->name, '@var')) {
$customTag = str_replace('@', '', $tagValue->name);
Expand Down
36 changes: 31 additions & 5 deletions tests/Unit/Analyzer/FileVisitorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ class ApplicationLevelDto
$this->assertCount(0, $violations);
}

public function test_it_parse_dependencies_in_docblocks(): void
public function test_it_parse_dependencies_in_docblocks_customs(): void
{
$code = <<< 'EOF'
<?php
Expand Down Expand Up @@ -649,17 +649,13 @@ public function test_should_implement_exact_classname(): void
{
$code = <<< 'EOF'
<?php
namespace Foo;
interface Order
{
}
interface OrderTwo
{
}
class test implements Order
{
}
Expand All @@ -678,4 +674,34 @@ class test implements Order

$this->assertCount(0, $violations, $violations->toString());
}

public function test_it_parse_dependencies_in_docblocks_with_alias(): void
{
$code = <<< 'EOF'
<?php
namespace MyProject\AppBundle\Application;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Test;
class ApplicationLevelDto
{
/**
* @Assert\NotBlank
*/
public string|null $foo;
}
EOF;

/** @var FileParser $fp */
$fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
$fp->parse($code, 'relativePathName');

$cd = $fp->getClassDescriptions();

$violations = new Violations();

$dependsOnTheseNamespaces = new DependsOnlyOnTheseNamespaces('MyProject\AppBundle\Application');
$dependsOnTheseNamespaces->evaluate($cd[0], $violations, 'we want to add this rule for our software');

$this->assertCount(1, $violations);
}
}

0 comments on commit 621cc7d

Please sign in to comment.