mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #1009 - improve handling of print_r
This commit is contained in:
parent
96768ffd48
commit
8e73b34469
@ -135,6 +135,22 @@ class FunctionChecker extends FunctionLikeChecker
|
||||
|
||||
return $call_map_key === 'var_export' ? Type::getVoid() : Type::getBool();
|
||||
|
||||
case 'print_r':
|
||||
if (isset($call_args[1]->value->inferredType)) {
|
||||
$subject_type = $call_args[1]->value->inferredType;
|
||||
|
||||
if ((string) $subject_type === 'true') {
|
||||
return Type::getString();
|
||||
}
|
||||
|
||||
return new Type\Union([
|
||||
new Type\Atomic\TString,
|
||||
new Type\Atomic\TTrue
|
||||
]);
|
||||
}
|
||||
|
||||
return Type::getTrue();
|
||||
|
||||
case 'getenv':
|
||||
return new Type\Union([new Type\Atomic\TString, new Type\Atomic\TFalse]);
|
||||
|
||||
|
@ -960,6 +960,14 @@ class FunctionCallTest extends TestCase
|
||||
'$d' => 'array<int, int>',
|
||||
],
|
||||
],
|
||||
'printrOutput' => [
|
||||
'<?php
|
||||
function foo(string $s) : void {
|
||||
echo $s;
|
||||
}
|
||||
|
||||
foo(print_r(1, true));',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user