phpat icon indicating copy to clipboard operation
phpat copied to clipboard

Method-scoped Attributes and Attribute parameters are not detected

Open darthf1 opened this issue 2 years ago • 2 comments

Hi!

I have a class in the Domain namespace, which has Doctrine's attributes for ORM mapping. My classes have the following imports:

<?php

declare(strict_types=1);

namespace Domain\MyDomain;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;

With the test below:

public function testDomainLayerOnlyDependsOnDomainLayer(): Rule
{
    return PHPat::rule()
        ->classes(
            Selector::namespace('/^Domain.*/', true),
        )
        ->shouldNotDependOn()
        ->classes(
            Selector::NOT(Selector::namespace('/^Domain.*/', true)),
        )
    ;
}

I get:

 ------ ------------------------------------------------------------------------------------------------- 
  Line   src/Domain/MyDomain\MyClass.php                                                           
 ------ ------------------------------------------------------------------------------------------------- 
  43     Domain\MyDomain\MyClass should not depend on Doctrine\DBAL\Types\Types                    
  48     Domain\MyDomain\MyClass should not depend on Doctrine\DBAL\Types\Types                    
  51     Domain\MyDomain\MyClass should not depend on Doctrine\DBAL\Types\Types                    
  54     Domain\MyDomain\MyClass should not depend on Doctrine\DBAL\Types\Types                    
  57     Domain\MyDomain\MyClass should not depend on Doctrine\DBAL\Types\Types                    
  60     Domain\MyDomain\MyClass should not depend on Doctrine\DBAL\Types\Types                    
  63     Domain\MyDomain\MyClass should not depend on Doctrine\DBAL\Types\Types                    
  69     Domain\MyDomain\MyClass should not depend on Doctrine\Common\Collections\Collection       
  75     Domain\MyDomain\MyClass should not depend on Doctrine\Common\Collections\Collection       
  95     Domain\MyDomain\MyClass should not depend on Doctrine\Common\Collections\ArrayCollection  
  102    Domain\MyDomain\MyClass should not depend on Doctrine\Common\Collections\ArrayCollection  
 ------ ------------------------------------------------------------------------------------------------- 

There is no mention of the import:

use Doctrine\ORM\Mapping as ORM;

Using a direct import also is not reported:

use Doctrine\ORM\Mapping\Column;

darthf1 avatar Dec 13 '22 20:12 darthf1