Skip to content

Commit 6b56599

Browse files
wip
1 parent 0487b72 commit 6b56599

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

src/Analyzer/NameResolver.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,17 @@ public function enterNode(Node $node)
142142
$tokenIterator = new TokenIterator($tokens);
143143
$phpDocNode = $phpDocParser->parse($tokenIterator);
144144

145-
foreach ($phpDocNode->getVarTagValues() as $tagValue) {
145+
foreach ($phpDocNode->getTags() as $tagValue) {
146+
if (!property_exists($tagValue, 'type')) {
147+
continue;
148+
}
149+
146150
$type = $this->resolveName(new Node\Name((string) $tagValue->type), Use_::TYPE_NORMAL);
147151
$node->type = $type;
148152
break;
149153
}
150154

151-
if (null === $node->type) {
155+
if (null === $node->type || !($node->type instanceof FullyQualified)) {
152156
foreach ($phpDocNode->getTags() as $tagValue) {
153157
if ('@' === $tagValue->name[0] && false === strpos($tagValue->name, '@var')) {
154158
$customTag = str_replace('@', '', $tagValue->name);

tests/Unit/Analyzer/FileVisitorTest.php

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,17 +649,13 @@ public function test_should_implement_exact_classname(): void
649649
{
650650
$code = <<< 'EOF'
651651
<?php
652-
653652
namespace Foo;
654-
655653
interface Order
656654
{
657655
}
658-
659656
interface OrderTwo
660657
{
661658
}
662-
663659
class test implements Order
664660
{
665661
}
@@ -678,4 +674,38 @@ class test implements Order
678674

679675
$this->assertCount(0, $violations, $violations->toString());
680676
}
677+
678+
public function test_it_parse_dependencies_in_docblocks_with_alias(): void
679+
{
680+
$code = <<< 'EOF'
681+
<?php
682+
namespace MyProject\AppBundle\Application;
683+
use Symfony\Component\Validator\Constraints as Assert;
684+
use Symfony\Test;
685+
class ApplicationLevelDto
686+
{
687+
/**
688+
* @Assert\NotBlank
689+
*/
690+
public string|null $foo;
691+
/**
692+
* @var Test
693+
*/
694+
public $bar;
695+
}
696+
EOF;
697+
698+
/** @var FileParser $fp */
699+
$fp = FileParserFactory::createFileParser(TargetPhpVersion::create('8.1'));
700+
$fp->parse($code, 'relativePathName');
701+
702+
$cd = $fp->getClassDescriptions();
703+
704+
$violations = new Violations();
705+
706+
$notHaveDependencyOutsideNamespace = new DependsOnlyOnTheseNamespaces('MyProject\AppBundle\Application');
707+
$notHaveDependencyOutsideNamespace->evaluate($cd[0], $violations, 'we want to add this rule for our software');
708+
709+
$this->assertCount(1, $violations);
710+
}
681711
}

0 commit comments

Comments
 (0)