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

Merge pull request #6089 from orklah/getTypeResourceClosed

Fix usage of gettype in a switch with closed resource
This commit is contained in:
Bruce Weirdan 2021-07-14 17:13:00 +03:00 committed by GitHub
commit 09b01677c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 2 deletions

View File

@ -2381,7 +2381,15 @@ class AssertionFinder
}
} else {
if ($var_name && $var_type) {
$if_types[$var_name] = [['!' . $var_type]];
if ($var_type === 'class@anonymous') {
$if_types[$var_name] = [['!=object']];
} elseif ($var_type === 'resource (closed)') {
$if_types[$var_name] = [['!closed-resource']];
} elseif (substr($var_type, 0, 10) === 'resource (') {
$if_types[$var_name] = [['!=resource']];
} else {
$if_types[$var_name] = [['!' . $var_type]];
}
}
}
@ -3054,7 +3062,15 @@ class AssertionFinder
}
} else {
if ($var_name && $var_type) {
$if_types[$var_name] = [[$var_type]];
if ($var_type === 'class@anonymous') {
$if_types[$var_name] = [['=object']];
} elseif ($var_type === 'resource (closed)') {
$if_types[$var_name] = [['closed-resource']];
} elseif (substr($var_type, 0, 10) === 'resource (') {
$if_types[$var_name] = [['=resource']];
} else {
$if_types[$var_name] = [[$var_type]];
}
}
}

View File

@ -792,6 +792,15 @@ class FunctionCallTest extends TestCase
if ($t === "object") {}
}',
],
'getTypeSwitchClosedResource' => [
'<?php
$data = "foo";
switch (gettype($data)) {
case "resource (closed)":
case "unknown type":
return "foo";
}',
],
'functionResolutionInNamespace' => [
'<?php
namespace Foo;