From 3c828c74b1905b877eccf94f7a7c87322cb411b6 Mon Sep 17 00:00:00 2001 From: kkmuffme <11071985+kkmuffme@users.noreply.github.com> Date: Wed, 13 Mar 2024 19:05:13 +0100 Subject: [PATCH] ParamNameMismatch not reported for __construct Fix https://github.com/vimeo/psalm/issues/10784 --- .../Internal/Analyzer/MethodComparator.php | 4 +++- tests/ClassTest.php | 23 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/MethodComparator.php b/src/Psalm/Internal/Analyzer/MethodComparator.php index 61726c5adbe..2ed47db5172 100644 --- a/src/Psalm/Internal/Analyzer/MethodComparator.php +++ b/src/Psalm/Internal/Analyzer/MethodComparator.php @@ -452,7 +452,9 @@ private static function compareMethodParams( && $implementer_classlike_storage->user_defined && $implementer_param->location && $guide_method_storage->cased_name - && strpos($guide_method_storage->cased_name, '__') !== 0 + && (strpos($guide_method_storage->cased_name, '__') !== 0 + || ($guide_classlike_storage->preserve_constructor_signature + && $guide_method_storage->cased_name === '__construct')) && $config->isInProjectDirs( $implementer_param->location->file_path, ) diff --git a/tests/ClassTest.php b/tests/ClassTest.php index d245fb44fc9..1d1984d4b12 100644 --- a/tests/ClassTest.php +++ b/tests/ClassTest.php @@ -985,6 +985,29 @@ class A {} echo A::HELLO;', 'error_message' => 'UndefinedConstant', ], + 'consistentNamesConstructor' => [ + 'code' => ' 'ParamNameMismatch', + ], 'overridePublicAccessLevelToPrivate' => [ 'code' => '