From c1e008e4f6c3b199b34b08eed41e8151f442970d Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 10 Jan 2022 12:35:45 +0100 Subject: [PATCH] PHP 8.1: Report missing typehints in overridden native methods --- .../Internal/Analyzer/MethodComparator.php | 28 +++++++++++++++++++ .../Type/Comparator/UnionTypeComparator.php | 2 +- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/Psalm/Internal/Analyzer/MethodComparator.php b/src/Psalm/Internal/Analyzer/MethodComparator.php index 0de16d9ef99..da8fdf02f39 100644 --- a/src/Psalm/Internal/Analyzer/MethodComparator.php +++ b/src/Psalm/Internal/Analyzer/MethodComparator.php @@ -116,6 +116,20 @@ public static function compare( ); } + if (!$guide_classlike_storage->user_defined + && $implementer_classlike_storage->user_defined + && $codebase->analysis_php_version_id >= 8_01_00 + && !$implementer_method_storage->signature_return_type + ) { + IssueBuffer::maybeAdd( + new MethodSignatureMismatch( + 'Method ' . $cased_implementer_method_id . ' is missing a return type signature!', + $implementer_method_storage->location + ), + $suppressed_issues + $implementer_classlike_storage->suppressed_issues + ); + } + if ($guide_method_storage->return_type && $implementer_method_storage->return_type && !$implementer_method_storage->inherited_return_type @@ -519,6 +533,20 @@ private static function compareMethodParams( $suppressed_issues + $implementer_classlike_storage->suppressed_issues ); } + + if (!$guide_classlike_storage->user_defined + && $implementer_classlike_storage->user_defined + && $codebase->analysis_php_version_id >= 8_01_00 + && !$implementer_param->signature_type + ) { + IssueBuffer::maybeAdd( + new MethodSignatureMismatch( + 'Argument ' . ($i + 1) . ' of ' . $cased_implementer_method_id . ' is missing a type signature!', + $implementer_param->location + ), + $suppressed_issues + $implementer_classlike_storage->suppressed_issues + ); + } } /** diff --git a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php index 288f3e25845..25a1d503583 100644 --- a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php @@ -303,7 +303,7 @@ public static function isContainedByInPhp( Union $container_type ): bool { if ($container_type->isMixed()) { - return true; + return !!$input_type; } if (!$input_type) {