File tree Expand file tree Collapse file tree 2 files changed +40
-6
lines changed Expand file tree Collapse file tree 2 files changed +40
-6
lines changed Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff line change @@ -649,17 +649,13 @@ public function test_should_implement_exact_classname(): void
649649 {
650650 $ code = <<< 'EOF'
651651<?php
652-
653652namespace Foo;
654-
655653interface Order
656654{
657655}
658-
659656interface OrderTwo
660657{
661658}
662-
663659class 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}
You can’t perform that action at this time.
0 commit comments