mirror of
https://github.com/danog/psalm.git
synced 2025-01-22 05:41:20 +01:00
Add support for special typeof types (used in get_class checks)
This commit is contained in:
parent
02ce85e383
commit
24d67e9615
@ -2909,21 +2909,14 @@ class StatementsChecker
|
||||
{
|
||||
$type_candidate_var = null;
|
||||
|
||||
if ($stmt->cond instanceof PhpParser\Node\Expr\FuncCall &&
|
||||
$stmt->cond->name instanceof PhpParser\Node\Name &&
|
||||
$stmt->cond->name->parts === ['get_class']) {
|
||||
|
||||
$var = $stmt->cond->args[0]->value;
|
||||
|
||||
if ($var instanceof PhpParser\Node\Expr\Variable && is_string($var->name)) {
|
||||
$type_candidate_var = $var->name;
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->_checkExpression($stmt->cond, $context) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isset($stmt->cond->inferredType) && array_values($stmt->cond->inferredType->types)[0] instanceof Type\T) {
|
||||
$type_candidate_var = array_values($stmt->cond->inferredType->types)[0]->typeof;
|
||||
}
|
||||
|
||||
$original_context = clone $context;
|
||||
|
||||
$case_types = [];
|
||||
@ -3239,6 +3232,14 @@ class StatementsChecker
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($stmt->name instanceof PhpParser\Node\Name && $stmt->name->parts === ['get_class']) {
|
||||
$var = $stmt->args[0]->value;
|
||||
|
||||
if ($var instanceof PhpParser\Node\Expr\Variable && is_string($var->name)) {
|
||||
$stmt->inferredType = new Type\Union([new Type\T($var->name)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
24
src/Psalm/Type/T.php
Normal file
24
src/Psalm/Type/T.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Psalm\Type;
|
||||
|
||||
use Psalm\Type;
|
||||
|
||||
class T extends Atomic
|
||||
{
|
||||
/**
|
||||
* Used to hold information as to what this refers to
|
||||
* @var string
|
||||
*/
|
||||
public $typeof;
|
||||
|
||||
/**
|
||||
* @param string $typeof the variable id
|
||||
*/
|
||||
public function __construct($typeof)
|
||||
{
|
||||
$this->value = 'string';
|
||||
|
||||
$this->typeof = $typeof;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user