phpat icon indicating copy to clipboard operation
phpat copied to clipboard

Interfaces extending other interfaces are not matched by shouldExtend()

Open InvisibleSmiley opened this issue 1 year ago • 0 comments

Bug Description AFAICS PHPat does not handle interfaces extending other interfaces correctly.

If a rule requires interfaces to extend a specific interface, even interfaces that fulfill the requirement are reported.

Note that interfaces may extend multiple other interfaces, and listing only one of them after shouldExtend() needs to work in that case.

Additional context

  1. Have a ValueObjectInterface somewhere
  2. Have other interfaces with suffix ValueObjectInterface somewhere that extend ValueObjectInterface
  3. Reference (import/use) the ValueObjectInterface in below test case
class MyArchTest {
    public function testValueObjectInterfacesExtendBaseInterface(): BuildStep
    {
        return PHPat::rule()
            ->classes(Selector::classname('/ValueObjectInterface$/', regex: true))
            ->excluding(Selector::classname(ValueObjectInterface::class))
            ->shouldExtend()
            ->classes(Selector::classname(ValueObjectInterface::class))
            ->because('Value object interfaces must extend ValueObjectInterface');
    }
}

InvisibleSmiley avatar Sep 25 '24 08:09 InvisibleSmiley