File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -147,6 +147,18 @@ public function enterNode(Node $node)
147147 $ node ->type = $ type ;
148148 break ;
149149 }
150+
151+ if (null === $ node ->type ) {
152+ foreach ($ phpDocNode ->getTags () as $ tagValue ) {
153+ if ('@ ' === $ tagValue ->name [0 ] && false === strpos ($ tagValue ->name , '@var ' )) {
154+ $ customTag = str_replace ('@ ' , '' , $ tagValue ->name );
155+ $ type = $ this ->resolveName (new Node \Name ($ customTag ), Use_::TYPE_NORMAL );
156+ $ node ->type = $ type ;
157+
158+ break ;
159+ }
160+ }
161+ }
150162 } elseif ($ node instanceof Stmt \Const_) {
151163 foreach ($ node ->consts as $ const ) {
152164 $ this ->addNamespacedName ($ const );
Original file line number Diff line number Diff line change @@ -613,4 +613,34 @@ class ApplicationLevelDto
613613
614614 $ this ->assertCount (1 , $ violations );
615615 }
616+
617+ public function test_it_parse_custom_tags_in_docblocks (): void
618+ {
619+ $ code = <<< 'EOF'
620+ <?php
621+ namespace MyProject\AppBundle\Application;
622+ use Symfony\Component\Validator\Constraints as Assert;
623+ class ApplicationLevelDto
624+ {
625+ /**
626+ * @Assert\NotBlank
627+ */
628+ public $foo;
629+
630+ }
631+ EOF;
632+
633+ /** @var FileParser $fp */
634+ $ fp = FileParserFactory::createFileParser (TargetPhpVersion::create ('8.1 ' ));
635+ $ fp ->parse ($ code , 'relativePathName ' );
636+
637+ $ cd = $ fp ->getClassDescriptions ();
638+
639+ $ violations = new Violations ();
640+
641+ $ notHaveDependencyOutsideNamespace = new DependsOnlyOnTheseNamespaces ('MyProject\AppBundle\Application ' );
642+ $ notHaveDependencyOutsideNamespace ->evaluate ($ cd [0 ], $ violations , 'we want to add this rule for our software ' );
643+
644+ $ this ->assertCount (1 , $ violations );
645+ }
616646}
You can’t perform that action at this time.
0 commit comments