1
0
mirror of https://github.com/danog/psalm.git synced 2025-01-21 21:31:13 +01:00

stub for is_a

This commit is contained in:
orklah 2021-10-12 20:13:04 +02:00
parent d54032078d
commit 1efe272aed
4 changed files with 13 additions and 3 deletions

View File

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

View File

@ -1294,3 +1294,10 @@ function get_meta_tags(string $filename, bool $use_include_path = false) : array
* @return ($categorize is false ? array<string,int|string|float|bool|null|array|resource> : array<string, array<string,int|string|float|bool|null|array|resource>>)
*/
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{}

View File

@ -189,8 +189,9 @@ class ClassTest extends TestCase
'returnStringAfterIsACheckWithString' => [
'<?php
class Foo{}
/** @param class-string $maybeBaz */
function bar(string $maybeBaz) : string {
if (!is_a($maybeBaz, "Foo", true)) {
if (!is_a($maybeBaz, Foo::class, true)) {
throw new Exception("not Foo");
}
return $maybeBaz;

View File

@ -324,7 +324,7 @@ class TraitTest extends TestCase
'<?php
trait T {
public function f(): void {
if (is_a(static::class, "B")) { }
if (is_a(static::class, B::class, true)) { }
}
}
@ -342,7 +342,7 @@ class TraitTest extends TestCase
'<?php
trait T {
public function f(): void {
if (is_a(static::class, "B")) { }
if (is_a(static::class, B::class, true)) { }
}
}