From 658d28716f4da8bead8bd5ffeecd5b642b652571 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Jul 2026 15:46:16 +0700 Subject: [PATCH 1/2] [perf] Reduce runtime instanceof check on loop violations on Analyser --- src/Analyser/Analyser.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Analyser/Analyser.php b/src/Analyser/Analyser.php index df6a044..f2bf82c 100644 --- a/src/Analyser/Analyser.php +++ b/src/Analyser/Analyser.php @@ -219,13 +219,13 @@ className: $violation->className, ? $rule->evaluateAll($classNode) : [$rule->evaluate($classNode)]; + if ($violations === [null]) { + continue; + } + $isFixable = $rule instanceof FixableInterface; foreach ($violations as $violation) { - if (! $violation instanceof RuleViolation) { - continue; - } - // Inject the rule key into the violation $ruleViolationCollection->add(new RuleViolation( message: $violation->message, From 613f9d734b8f08562c42c92814fe120da10b69ad Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 14 Jul 2026 15:50:02 +0700 Subject: [PATCH 2/2] fix phpstan --- src/Analyser/Analyser.php | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Analyser/Analyser.php b/src/Analyser/Analyser.php index f2bf82c..db61b1a 100644 --- a/src/Analyser/Analyser.php +++ b/src/Analyser/Analyser.php @@ -215,12 +215,15 @@ className: $violation->className, continue; } - $violations = $rule instanceof MultipleRuleViolationInterface - ? $rule->evaluateAll($classNode) - : [$rule->evaluate($classNode)]; + if ($rule instanceof MultipleRuleViolationInterface) { + $violations = $rule->evaluateAll($classNode); + } else { + $violation = $rule->evaluate($classNode); + if (! $violation instanceof RuleViolation) { + continue; + } - if ($violations === [null]) { - continue; + $violations = [$violation]; } $isFixable = $rule instanceof FixableInterface;