Skip to content

Commit

Permalink
Fix thing that doesn’t work quite right
Browse files Browse the repository at this point in the history
  • Loading branch information
muglug committed Jan 5, 2019
1 parent 4d6031b commit e3f2cee
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 39 deletions.
35 changes: 8 additions & 27 deletions src/Psalm/Internal/Analyzer/FunctionAnalyzer.php
Expand Up @@ -608,33 +608,14 @@ public static function getReturnTypeFromCallMapWithArgs(
return self::getFilterVar($call_args);

case 'get_parent_class':
$codebase = $statements_analyzer->getCodebase();

$first_arg = $call_args[0]->value;

if (isset($first_arg->inferredType)) {
$class_strings = [];

foreach ($first_arg->inferredType->getTypes() as $atomic_type) {
if ($atomic_type instanceof Type\Atomic\TNamedObject
&& $codebase->classExists($atomic_type->value)
) {
$classlike_storage = $codebase->classlike_storage_provider->get($atomic_type->value);

if ($classlike_storage->parent_classes) {
$class_strings[] = new Type\Atomic\TClassString(
array_values($classlike_storage->parent_classes)[0]
);
}
}
}

if ($class_strings) {
return \Psalm\Internal\Type\TypeCombination::combineTypes(
$class_strings
);
}
}
// this is unreliable, as it's hard to know exactly what's wanted - attempted this in
// https://github.com/vimeo/psalm/commit/355ed831e1c69c96bbf9bf2654ef64786cbe9fd7
// but caused problems where it didn’t know exactly what level of child we
// were receiving.
//
// Really this should only work on instances we've created with new Foo(),
// but that requires more work
break;
}
}

Expand Down
12 changes: 0 additions & 12 deletions tests/ClassStringTest.php
Expand Up @@ -344,18 +344,6 @@ function foo(A $a) : string {
return get_class($a);
}',
],
'returnGetParentClassClassStringParameterizedWithArg' => [
'<?php
class A {}
class B extends A {}
/**
* @return class-string<A> $s
*/
function foo(B $b) : string {
return get_parent_class($b);
}',
],
'returnGetParentClassClassStringParameterizedNoArg' => [
'<?php
class A {}
Expand Down

0 comments on commit e3f2cee

Please sign in to comment.