From 6269b804a07ab36f6f6f6593e279f22472a236dc Mon Sep 17 00:00:00 2001 From: Evan Shaw Date: Tue, 26 Mar 2024 08:31:33 +1300 Subject: [PATCH] Don't emit MissingOverrideAttribute for implicit Stringable implementations --- .../Analyzer/FunctionLikeAnalyzer.php | 2 ++ tests/OverrideTest.php | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index c38849ff6..b6d941e98 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -1996,6 +1996,8 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer && $codebase->config->ensure_override_attribute && $overridden_method_ids && $storage->cased_name !== '__construct' + && ($storage->cased_name !== '__toString' + || isset($appearing_class_storage->direct_class_interfaces['stringable'])) ) { IssueBuffer::maybeAdd( new MissingOverrideAttribute( diff --git a/tests/OverrideTest.php b/tests/OverrideTest.php index f46f55cfa..c64c0491c 100644 --- a/tests/OverrideTest.php +++ b/tests/OverrideTest.php @@ -85,6 +85,19 @@ class OverrideTest extends TestCase 'ignored_issues' => [], 'php_version' => '8.3', ], + 'ignoreImplicitStringable' => [ + 'code' => ' + [], + 'ignored_issues' => [], + 'php_version' => '8.3', + ], ]; } @@ -190,6 +203,19 @@ class OverrideTest extends TestCase 'error_levels' => [], 'php_version' => '8.3', ], + 'explicitStringable' => [ + 'code' => ' + 'MissingOverrideAttribute', + 'error_levels' => [], + 'php_version' => '8.3', + ], ]; } }