Skip to content

Commit

Permalink
PHP 8.1: Report missing typehints in overridden native methods
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Jan 10, 2022
1 parent 549c02d commit b317874
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/Psalm/Internal/Analyzer/MethodComparator.php
Expand Up @@ -113,6 +113,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
Expand Down Expand Up @@ -516,6 +530,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
);
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php
Expand Up @@ -303,7 +303,7 @@ public static function isContainedByInPhp(
Union $container_type
): bool {
if ($container_type->isMixed()) {
return true;
return !!$input_type;
}

if (!$input_type) {
Expand Down

0 comments on commit b317874

Please sign in to comment.