From 4e04201f2b52f0054ac18bce6ea50b5440645351 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Thu, 4 Apr 2024 18:25:51 +0200 Subject: [PATCH] qa: replace PHPStan ignore annotation by `phpstan-assert-if-true` --- src/Type/Parser/Lexer/Token/ObjectToken.php | 2 +- src/Type/Parser/Lexer/Token/VacantToken.php | 2 -- src/Utility/Reflection/Reflection.php | 6 ++++++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Type/Parser/Lexer/Token/ObjectToken.php b/src/Type/Parser/Lexer/Token/ObjectToken.php index 4141dc83..852978f3 100644 --- a/src/Type/Parser/Lexer/Token/ObjectToken.php +++ b/src/Type/Parser/Lexer/Token/ObjectToken.php @@ -19,7 +19,7 @@ public function __construct( public function traverse(TokenStream $stream): Type { return Reflection::enumExists($this->className) - ? (new EnumNameToken($this->className))->traverse($stream) // @phpstan-ignore-line / We know `$this->className` matches `class-string` + ? (new EnumNameToken($this->className))->traverse($stream) : (new ClassNameToken($this->className))->traverse($stream); } diff --git a/src/Type/Parser/Lexer/Token/VacantToken.php b/src/Type/Parser/Lexer/Token/VacantToken.php index 53b2d0be..f3fa0c36 100644 --- a/src/Type/Parser/Lexer/Token/VacantToken.php +++ b/src/Type/Parser/Lexer/Token/VacantToken.php @@ -32,12 +32,10 @@ public function traverse(TokenStream $stream): Type } if (Reflection::enumExists($this->symbol)) { - // @phpstan-ignore-next-line / We know `$this->symbol` matches `class-string` return (new EnumNameToken($this->symbol))->traverse($stream); } if (Reflection::classOrInterfaceExists($this->symbol)) { - // @phpstan-ignore-next-line / We know `$this->symbol` matches `class-string` return (new ClassNameToken($this->symbol))->traverse($stream); } diff --git a/src/Utility/Reflection/Reflection.php b/src/Utility/Reflection/Reflection.php index 9d035b5a..600cf5ee 100644 --- a/src/Utility/Reflection/Reflection.php +++ b/src/Utility/Reflection/Reflection.php @@ -19,6 +19,7 @@ use ReflectionType; use ReflectionUnionType; use Reflector; +use UnitEnum; use function array_filter; use function array_map; @@ -47,6 +48,8 @@ final class Reflection /** * Case-sensitive implementation of `class_exists` and `interface_exists`. + * + * @phpstan-assert-if-true class-string $name */ public static function classOrInterfaceExists(string $name): bool { @@ -55,6 +58,9 @@ public static function classOrInterfaceExists(string $name): bool && self::class($name)->name === ltrim($name, '\\'); } + /** + * @phpstan-assert-if-true class-string $name + */ public static function enumExists(string $name): bool { // @infection-ignore-all / We don't need to test the cache