Skip to content
Permalink
Browse files

Support existing concatenation more better

  • Loading branch information...
muglug committed Aug 20, 2019
1 parent 73f245f commit 302ed4b21b202587fec3b4c76425dc86fa5fa96f
Showing with 38 additions and 6 deletions.
  1. +28 −6 src/Psalm/Internal/Type/AssertionReconciler.php
  2. +10 −0 tests/MethodCallTest.php
@@ -820,12 +820,34 @@ private static function reconcileHasMethod(
$object_types[] = $type;
if (!$codebase->methodExists($type->value . '::' . $method_name)) {
$obj = new Atomic\TObjectWithProperties(
[],
[$method_name => $type->value . '::' . $method_name]
);
$type->extra_types[$obj->getKey()] = $obj;
$did_remove_type = true;
$match_found = false;
if ($type->extra_types) {
foreach ($type->extra_types as $extra_type) {
if ($extra_type instanceof TNamedObject
&& $codebase->classOrInterfaceExists($extra_type->value)
&& $codebase->methodExists($extra_type->value . '::' . $method_name)
) {
$match_found = true;
} elseif ($extra_type instanceof Atomic\TObjectWithProperties) {
$match_found = true;
if (!isset($extra_type->methods[$method_name])) {
$extra_type->methods[$method_name] = 'object::' . $method_name;
$did_remove_type = true;
}
}
}
}
if (!$match_found) {
$obj = new Atomic\TObjectWithProperties(
[],
[$method_name => $type->value . '::' . $method_name]
);
$type->extra_types[$obj->getKey()] = $obj;
$did_remove_type = true;
}
}
} elseif ($type instanceof Atomic\TObjectWithProperties) {
$object_types[] = $type;
@@ -388,6 +388,16 @@ function foo(object $object) : void {
}
}'
],
'callManyMethodsOnKnownObjectAfterCheckingExistenceChained' => [
'<?php
class A {}
function foo(A $object) : void {
if (method_exists($object, "foo") && method_exists($object, "bar")) {
$object->foo();
$object->bar();
}
}'
],
];
}

0 comments on commit 302ed4b

Please sign in to comment.
You can’t perform that action at this time.