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

new Implement(\Throwable:;class) doesn't work as expected and has false positives #393

Open
Et3rnel opened this issue Jul 19, 2023 · 1 comment

Comments

@Et3rnel
Copy link

Et3rnel commented Jul 19, 2023

Bug Report

Q A
BC Break yes?
Library Version 0.3.25
PHP version 8.2

Summary

I try to check if all my exceptions are suffixed by Exception keyword

Current behavior

All interfaces and traits seems to be flagged as violation

How to reproduce

Create this rule:

$rules[] = Rule::allClasses()
    ->that(new Implement(\Throwable::class))
    // also doesn't work with ->that(new Implement('Throwable'))
    // also doesn't work with ->that(new Extend(\Exception::class))
    ->should(new HaveNameMatching('*Exception'))
    ->because('reasons');

Expected behavior

  • The exceptions not suffixing Exception should be flagged as violations (that's not the case)
  • All interfaces and traits should not be flagged as violations (because they don't event extend Throwable in my case)
@notcgi
Copy link
Contributor

notcgi commented Mar 19, 2024

That works fine

phparkitect.php:

return static function (Config $config): void {
    $classSet = ClassSet::fromDir(__DIR__.'/src');
    $rules[] = Rule::allClasses()
        ->that(new Extend(\Exception::class))
        ->should(new HaveNameMatching('*Exception'))
        ->because('reasons');
    $config->add($classSet, ...$rules);
};

src/Wrong.php:

class Wrong extends \Exception{}

Output:

ERRORS!

src\Wrong has 1 violations
  should have a name that matches *Exception because reasons

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants