mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Add better support for get_debug_type
This commit is contained in:
parent
0f8b017384
commit
c00bc4ee51
@ -2725,7 +2725,8 @@ class AssertionFinder
|
||||
&& $conditional->right->name instanceof PhpParser\Node\Name
|
||||
&& strtolower($conditional->right->name->parts[0]) === 'get_debug_type'
|
||||
&& $conditional->right->args
|
||||
&& $conditional->left instanceof PhpParser\Node\Scalar\String_
|
||||
&& ($conditional->left instanceof PhpParser\Node\Scalar\String_
|
||||
|| $conditional->left instanceof PhpParser\Node\Expr\ClassConstFetch)
|
||||
) {
|
||||
return self::ASSIGNMENT_TO_RIGHT;
|
||||
}
|
||||
@ -2734,7 +2735,8 @@ class AssertionFinder
|
||||
&& $conditional->left->name instanceof PhpParser\Node\Name
|
||||
&& strtolower($conditional->left->name->parts[0]) === 'get_debug_type'
|
||||
&& $conditional->left->args
|
||||
&& $conditional->right instanceof PhpParser\Node\Scalar\String_
|
||||
&& ($conditional->right instanceof PhpParser\Node\Scalar\String_
|
||||
|| $conditional->right instanceof PhpParser\Node\Expr\ClassConstFetch)
|
||||
) {
|
||||
return self::ASSIGNMENT_TO_LEFT;
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ use Psalm\Type\Atomic\TFloat;
|
||||
use Psalm\Type\Atomic\TTemplateParam;
|
||||
use Psalm\Type\Atomic\TTemplateParamClass;
|
||||
use Psalm\Type\Atomic\TDependentGetClass;
|
||||
use Psalm\Type\Atomic\TDependentGetDebugType;
|
||||
use Psalm\Type\Atomic\TDependentGetType;
|
||||
use Psalm\Type\Atomic\THtmlEscapedString;
|
||||
use Psalm\Type\Atomic\TInt;
|
||||
@ -151,6 +152,18 @@ class ScalarTypeComparator
|
||||
}
|
||||
}
|
||||
|
||||
if ($container_type_part instanceof TDependentGetDebugType) {
|
||||
if ($container_type_part instanceof TClassString || $container_type_part instanceof TLiteralClassString) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $input_type_part instanceof TString;
|
||||
}
|
||||
|
||||
if ($input_type_part instanceof TDependentGetDebugType) {
|
||||
$input_type_part = new TString();
|
||||
}
|
||||
|
||||
if ($container_type_part instanceof TDependentGetType) {
|
||||
$container_type_part = new TString();
|
||||
|
||||
|
@ -1379,6 +1379,23 @@ class FunctionCallTest extends TestCase
|
||||
return mb_convert_encoding($str, "UTF-8", "UTF-8");
|
||||
}'
|
||||
],
|
||||
'getDebugType' => [
|
||||
'<?php
|
||||
function foo(mixed $var) : void {
|
||||
switch (get_debug_type($var)) {
|
||||
case "string":
|
||||
echo "a string";
|
||||
break;
|
||||
|
||||
case Exception::class;
|
||||
echo "an Exception with message " . $var->getMessage();
|
||||
break;
|
||||
}
|
||||
}',
|
||||
[],
|
||||
[],
|
||||
'8.0'
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user