phparkitect / arkitect

Put your architectural rules under test!
MIT License
703 stars 36 forks source link

False positives for IsAbstract expression #434

Open davidcv91 opened 3 months ago

davidcv91 commented 3 months ago

Bug Report

Q A
BC Break yes
Library Version 0.3.33
PHP version 8.1.28

Summary

IsAbstract() finds classes that are not abstract

Apparently, the bug was added on this commit

Current behavior

App\MyClass has 1 violations
  should have a name that matches Abstract* because we want to prefix abstract classes

How to reproduce

Add the following rule:

Rule::allClasses()
        ->that(new IsAbstract())
        ->should(new HaveNameMatching('Abstract*'))
        ->because('we want to prefix abstract classes');

And create a class like:

final class MyClass
{
}

Expected behavior

No errors reported

courtney-miles commented 1 month ago

I have also found this to be unexpected matching and am compensating by specifically excluding everything else:

Rule::allClasses()
        ->that(new IsAbstract())
        ->that(new IsNotInterface())
        ->that(new IsNotTrait())
        ->that(new IsNotFinal())
        ->should(new HaveNameMatching('Abstract*'))
        ->because('we want to prefix abstract classes');

I'm trying to understand what problem #425 will have fixed and can't see it.