Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Method-scoped Attributes and Attribute parameters are not detected #203

Open
darthf1 opened this issue Dec 13, 2022 · 2 comments
Open

Method-scoped Attributes and Attribute parameters are not detected #203

darthf1 opened this issue Dec 13, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@darthf1
Copy link

darthf1 commented Dec 13, 2022

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 darthf1 added the bug Something isn't working label Dec 13, 2022
@carlosas
Copy link
Owner

I don't think imports should be reported. However, used attributes should, but the rule is still not created.
I will keep this issue open for that matter, as it's something I'm planning to do soon.

@carlosas carlosas changed the title Attribute imports are not detected Attributes are not detected Dec 29, 2022
@carlosas
Copy link
Owner

carlosas commented Apr 2, 2023

Class-scoped Attributes should be catch now with https://github.com/carlosas/phpat/releases/tag/0.10.4
However, method-scoped Attributes and Attribute parameters are not implemented yet

@carlosas carlosas changed the title Attributes are not detected Method-scoped Attributes and Attribute parameters are not detected Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants