From 1efe272aede04fe1a0bc7aeecdca41aade24a29c Mon Sep 17 00:00:00 2001 From: orklah Date: Tue, 12 Oct 2021 20:13:04 +0200 Subject: [PATCH] stub for is_a --- src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php | 2 ++ stubs/CoreGenericFunctions.phpstub | 7 +++++++ tests/ClassTest.php | 3 ++- tests/TraitTest.php | 4 ++-- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php index 5223e1126..253231bda 100644 --- a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php @@ -11,6 +11,7 @@ use Psalm\Type\Union; use function array_merge; use function array_values; +use function class_exists; use function count; use function is_a; use function reset; @@ -488,6 +489,7 @@ class TemplateStandinTypeReplacer continue; } + /** @var class-string $key may not always be true but class_exists on built in classes(Iterator) is wrong */ if (is_a($input_key, $key, true)) { $matching_atomic_types[$atomic_input_type->getId()] = $atomic_input_type; continue; diff --git a/stubs/CoreGenericFunctions.phpstub b/stubs/CoreGenericFunctions.phpstub index e893eead1..b7b4ecef4 100644 --- a/stubs/CoreGenericFunctions.phpstub +++ b/stubs/CoreGenericFunctions.phpstub @@ -1294,3 +1294,10 @@ function get_meta_tags(string $filename, bool $use_include_path = false) : array * @return ($categorize is false ? array : array>) */ function get_defined_constants(bool $categorize = false): array {} + +/** + * @param mixed $object + * @param class-string $class_name + * @return ($allow_string is false ? ($object is class-string ? false : bool) : bool) + */ +function is_a($object, string $class_name, $allow_string = false): bool{} \ No newline at end of file diff --git a/tests/ClassTest.php b/tests/ClassTest.php index 03d7abc35..227e50c4c 100644 --- a/tests/ClassTest.php +++ b/tests/ClassTest.php @@ -189,8 +189,9 @@ class ClassTest extends TestCase 'returnStringAfterIsACheckWithString' => [ '