Skip to content

feat: add ExtendedClassAwareRuleInterface to detect extended classes#219

Merged
samsonasik merged 6 commits into
mainfrom
extended
Jul 19, 2026
Merged

feat: add ExtendedClassAwareRuleInterface to detect extended classes#219
samsonasik merged 6 commits into
mainfrom
extended

Conversation

@samsonasik

@samsonasik samsonasik commented Jul 19, 2026

Copy link
Copy Markdown
Member

This PR introduces Boundwize\StructArmed\Rule\ExtendedClassAwareRuleInterface.

A marker that lets a rule know whether the class it's evaluating is extended by another scanned class, and applies it to Boundwize\StructArmed\Rule\Rules\Class_\MustBeFinalRule.

Using interface in custom rule:

use Boundwize\StructArmed\Analyser\ClassNode;
use Boundwize\StructArmed\Rule\ExtendedClassAwareRuleInterface;
use Boundwize\StructArmed\Rule\RuleViolation;

final readonly class MyRule implements ExtendedClassAwareRuleInterface
{
    public function appliesTo(ClassNode $classNode): bool
    {
        return $classNode->isClass();
    }

    public function evaluate(ClassNode $classNode): ?RuleViolation
    {
        // Skip classes that another scanned class extends.
        if ($classNode->isExtended) {
            return null;
        }

        // other check ...

        return new RuleViolation(
            ...
        );
    }
}

@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@samsonasik
samsonasik merged commit f11addd into main Jul 19, 2026
14 checks passed
@samsonasik
samsonasik deleted the extended branch July 19, 2026 05:16
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

Successfully merging this pull request may close these issues.

1 participant