mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Add support for get_parent_class() with no args
This commit is contained in:
parent
d85c9d8aa2
commit
58acaefe70
@ -82,6 +82,24 @@ class FunctionAnalyzer extends FunctionLikeAnalyzer
|
||||
|
||||
case 'microtime':
|
||||
return Type::getString();
|
||||
|
||||
case 'get_called_class':
|
||||
return new Type\Union([new Type\Atomic\TClassString($context->self ?: 'object')]);
|
||||
|
||||
case 'get_parent_class':
|
||||
$codebase = $statements_analyzer->getCodebase();
|
||||
|
||||
if ($context->self && $codebase->classExists($context->self)) {
|
||||
$classlike_storage = $codebase->classlike_storage_provider->get($context->self);
|
||||
|
||||
if ($classlike_storage->parent_classes) {
|
||||
return new Type\Union([
|
||||
new Type\Atomic\TClassString(
|
||||
array_values($classlike_storage->parent_classes)[0]
|
||||
)
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch ($call_map_key) {
|
||||
|
@ -322,6 +322,17 @@ class ClassStringTest extends TestCase
|
||||
return $a::class;
|
||||
}',
|
||||
],
|
||||
'returnGetCalledClassClassStringParameterized' => [
|
||||
'<?php
|
||||
class A {
|
||||
/**
|
||||
* @return class-string<A> $s
|
||||
*/
|
||||
function foo() : string {
|
||||
return get_called_class();
|
||||
}
|
||||
}',
|
||||
],
|
||||
'returnGetClassClassStringParameterized' => [
|
||||
'<?php
|
||||
class A {}
|
||||
@ -333,6 +344,19 @@ class ClassStringTest extends TestCase
|
||||
return get_class($a);
|
||||
}',
|
||||
],
|
||||
'returnGetParentClassClassStringParameterized' => [
|
||||
'<?php
|
||||
class A {}
|
||||
|
||||
class B extends A {
|
||||
/**
|
||||
* @return class-string<A> $s
|
||||
*/
|
||||
function foo() : string {
|
||||
return get_parent_class();
|
||||
}
|
||||
}',
|
||||
],
|
||||
'createClassOfTypeFromString' => [
|
||||
'<?php
|
||||
class A {}
|
||||
|
Loading…
Reference in New Issue
Block a user