mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Merge pull request #6089 from orklah/getTypeResourceClosed
Fix usage of gettype in a switch with closed resource
This commit is contained in:
commit
09b01677c0
@ -2381,9 +2381,17 @@ class AssertionFinder
|
||||
}
|
||||
} else {
|
||||
if ($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]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $if_types ? [$if_types] : [];
|
||||
}
|
||||
@ -3054,9 +3062,17 @@ class AssertionFinder
|
||||
}
|
||||
} else {
|
||||
if ($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]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $if_types ? [$if_types] : [];
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user