1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-26 20:34:47 +01:00

Fix #1009 - improve handling of print_r

This commit is contained in:
Brown 2018-10-10 10:58:47 -04:00
parent 96768ffd48
commit 8e73b34469
2 changed files with 24 additions and 0 deletions

View File

@ -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]);

View File

@ -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));',
],
];
}