From 32eaf12d40c8d0e47540bfdac0f8fd12f72afbf1 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Sun, 11 Dec 2022 05:49:09 -0400 Subject: [PATCH] Prevent duplicate (Possibly)UnusedMethod/(Possibly)UnusedProperty This also allows (Possibly)UnusedProperty to be suppressed with `referencedProperty` attribute in psalm.xml Fixes vimeo/psalm#8874 --- src/Psalm/Internal/Codebase/ClassLikes.php | 6 ++++-- src/Psalm/Issue/PossiblyUnusedMethod.php | 13 +++++++++++++ src/Psalm/Issue/PossiblyUnusedProperty.php | 13 ++++++++++++- src/Psalm/Issue/UnusedMethod.php | 13 +++++++++++++ src/Psalm/Issue/UnusedProperty.php | 13 ++++++++++++- 5 files changed, 54 insertions(+), 4 deletions(-) diff --git a/src/Psalm/Internal/Codebase/ClassLikes.php b/src/Psalm/Internal/Codebase/ClassLikes.php index 664605ff5c4..1a9bb459388 100644 --- a/src/Psalm/Internal/Codebase/ClassLikes.php +++ b/src/Psalm/Internal/Codebase/ClassLikes.php @@ -2144,7 +2144,8 @@ private function checkPropertyReferences(ClassLikeStorage $classlike_storage): v 'Cannot find ' . ($has_variable_calls ? 'explicit' : 'any') . ' references to property ' . $property_id . ($has_variable_calls ? ' (but did find some potential references)' : ''), - $property_storage->location + $property_storage->location, + $property_id ); if ($codebase->alter_code) { @@ -2173,7 +2174,8 @@ private function checkPropertyReferences(ClassLikeStorage $classlike_storage): v 'Cannot find ' . ($has_variable_calls ? 'explicit' : 'any') . ' references to private property ' . $property_id . ($has_variable_calls ? ' (but did find some potential references)' : ''), - $property_storage->location + $property_storage->location, + $property_id ); if ($codebase->alter_code) { diff --git a/src/Psalm/Issue/PossiblyUnusedMethod.php b/src/Psalm/Issue/PossiblyUnusedMethod.php index 17d5b07e750..1e85e9a9c44 100644 --- a/src/Psalm/Issue/PossiblyUnusedMethod.php +++ b/src/Psalm/Issue/PossiblyUnusedMethod.php @@ -2,8 +2,21 @@ namespace Psalm\Issue; +use Psalm\CodeLocation; + +use function strtolower; + final class PossiblyUnusedMethod extends MethodIssue { public const ERROR_LEVEL = -2; public const SHORTCODE = 87; + + public function __construct( + string $message, + CodeLocation $code_location, + string $method_id + ) { + parent::__construct($message, $code_location, $method_id); + $this->dupe_key = strtolower($method_id); + } } diff --git a/src/Psalm/Issue/PossiblyUnusedProperty.php b/src/Psalm/Issue/PossiblyUnusedProperty.php index 08562534465..bb806a48e14 100644 --- a/src/Psalm/Issue/PossiblyUnusedProperty.php +++ b/src/Psalm/Issue/PossiblyUnusedProperty.php @@ -2,8 +2,19 @@ namespace Psalm\Issue; -final class PossiblyUnusedProperty extends CodeIssue +use Psalm\CodeLocation; + +final class PossiblyUnusedProperty extends PropertyIssue { public const ERROR_LEVEL = -2; public const SHORTCODE = 149; + + public function __construct( + string $message, + CodeLocation $code_location, + string $property_id + ) { + parent::__construct($message, $code_location, $property_id); + $this->dupe_key = $property_id; + } } diff --git a/src/Psalm/Issue/UnusedMethod.php b/src/Psalm/Issue/UnusedMethod.php index 2e72d433d6a..878d0a189aa 100644 --- a/src/Psalm/Issue/UnusedMethod.php +++ b/src/Psalm/Issue/UnusedMethod.php @@ -2,8 +2,21 @@ namespace Psalm\Issue; +use Psalm\CodeLocation; + +use function strtolower; + final class UnusedMethod extends MethodIssue { public const ERROR_LEVEL = -2; public const SHORTCODE = 76; + + public function __construct( + string $message, + CodeLocation $code_location, + string $method_id + ) { + parent::__construct($message, $code_location, $method_id); + $this->dupe_key = strtolower($method_id); + } } diff --git a/src/Psalm/Issue/UnusedProperty.php b/src/Psalm/Issue/UnusedProperty.php index 273f227223c..f3281ef94d7 100644 --- a/src/Psalm/Issue/UnusedProperty.php +++ b/src/Psalm/Issue/UnusedProperty.php @@ -2,8 +2,19 @@ namespace Psalm\Issue; -final class UnusedProperty extends CodeIssue +use Psalm\CodeLocation; + +final class UnusedProperty extends PropertyIssue { public const ERROR_LEVEL = -2; public const SHORTCODE = 150; + + public function __construct( + string $message, + CodeLocation $code_location, + string $property_id + ) { + parent::__construct($message, $code_location, $property_id); + $this->dupe_key = $property_id; + } }