mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix resolution of get_called_class
This commit is contained in:
parent
3253f57c94
commit
ae31ec6805
@ -89,7 +89,12 @@ class FunctionAnalyzer extends FunctionLikeAnalyzer
|
||||
]);
|
||||
|
||||
case 'get_called_class':
|
||||
return new Type\Union([new Type\Atomic\TClassString($context->self ?: 'object')]);
|
||||
return new Type\Union([
|
||||
new Type\Atomic\TClassString(
|
||||
$context->self ?: 'object',
|
||||
$context->self ? new Type\Atomic\TNamedObject($context->self, true) : null
|
||||
)
|
||||
]);
|
||||
|
||||
case 'get_parent_class':
|
||||
if ($context->self && $codebase->classExists($context->self)) {
|
||||
|
@ -28,13 +28,14 @@ class TNamedObject extends Atomic
|
||||
/**
|
||||
* @param string $value the name of the object
|
||||
*/
|
||||
public function __construct($value)
|
||||
public function __construct($value, bool $was_static = false)
|
||||
{
|
||||
if ($value[0] === '\\') {
|
||||
$value = substr($value, 1);
|
||||
}
|
||||
|
||||
$this->value = $value;
|
||||
$this->was_static = $was_static;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
|
@ -738,6 +738,16 @@ class ClassStringTest extends TestCase
|
||||
}
|
||||
}'
|
||||
],
|
||||
'getCalledClassIsStaticClass' => [
|
||||
'<?php
|
||||
class A {
|
||||
/** @return static */
|
||||
public function getStatic() {
|
||||
$c = get_called_class();
|
||||
return new $c();
|
||||
}
|
||||
}'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user