From bcfa0a0ca5c2610422a141d6430727738dbcda36 Mon Sep 17 00:00:00 2001 From: Jan Nedbal Date: Tue, 5 Nov 2024 10:28:57 +0100 Subject: [PATCH] Disable mixed calls diagnosis for `trackMixedCalls: false` (#109) --- rules.neon | 1 + src/Rule/DeadMethodRule.php | 8 ++++++-- tests/Rule/DeadMethodRuleTest.php | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/rules.neon b/rules.neon index 8ec43cb..439e808 100644 --- a/rules.neon +++ b/rules.neon @@ -74,6 +74,7 @@ services: - phpstan.diagnoseExtension arguments: reportTransitivelyDeadMethodAsSeparateError: %shipmonkDeadCode.reportTransitivelyDeadMethodAsSeparateError% + trackCallsOnMixed: %shipmonkDeadCode.trackCallsOnMixed% parameters: diff --git a/src/Rule/DeadMethodRule.php b/src/Rule/DeadMethodRule.php index df2d71b..3d81b24 100644 --- a/src/Rule/DeadMethodRule.php +++ b/src/Rule/DeadMethodRule.php @@ -79,6 +79,8 @@ class DeadMethodRule implements Rule, DiagnoseExtension private bool $reportTransitivelyDeadMethodAsSeparateError; + private bool $trackCallsOnMixed; + /** * @var array methodKey => [file, line] */ @@ -96,11 +98,13 @@ class DeadMethodRule implements Rule, DiagnoseExtension public function __construct( ClassHierarchy $classHierarchy, - bool $reportTransitivelyDeadMethodAsSeparateError + bool $reportTransitivelyDeadMethodAsSeparateError, + bool $trackCallsOnMixed ) { $this->classHierarchy = $classHierarchy; $this->reportTransitivelyDeadMethodAsSeparateError = $reportTransitivelyDeadMethodAsSeparateError; + $this->trackCallsOnMixed = $trackCallsOnMixed; } public function getNodeType(): string @@ -558,7 +562,7 @@ private function isNeverReportedAsDead(string $methodKey): bool public function print(Output $output): void { - if ($this->mixedCalls === [] || !$output->isDebug()) { + if ($this->mixedCalls === [] || !$output->isDebug() || !$this->trackCallsOnMixed) { return; } diff --git a/tests/Rule/DeadMethodRuleTest.php b/tests/Rule/DeadMethodRuleTest.php index f8a0d1e..266cb55 100644 --- a/tests/Rule/DeadMethodRuleTest.php +++ b/tests/Rule/DeadMethodRuleTest.php @@ -54,6 +54,7 @@ protected function getRule(): DeadMethodRule $this->rule = new DeadMethodRule( new ClassHierarchy(), !$this->emitErrorsInGroups, + true, ); }