1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-22 05:41:20 +01:00

Do not provide mixed return type on unrelated methods (#5895)

Fixes vimeo/psalm#5894
This commit is contained in:
Bruce Weirdan 2021-06-07 17:45:43 +03:00 committed by GitHub
parent 3ad3375777
commit a5080f2cf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -16,14 +16,18 @@ class DomNodeAppendChild implements \Psalm\Plugin\EventHandler\MethodReturnTypeP
$source = $event->getSource();
$call_args = $event->getCallArgs();
$method_name_lowercase = $event->getMethodNameLowercase();
if ($method_name_lowercase !== 'appendchild') {
return null;
}
if (!$source instanceof \Psalm\Internal\Analyzer\StatementsAnalyzer
|| !$call_args
) {
return Type::getMixed();
}
if ($method_name_lowercase === 'appendchild'
&& ($first_arg_type = $source->node_data->getType($call_args[0]->value))
if (($first_arg_type = $source->node_data->getType($call_args[0]->value))
&& $first_arg_type->hasObjectType()
) {
return clone $first_arg_type;