Skip to content

Commit

Permalink
qa: replace PHPStan ignore annotation by phpstan-assert-if-true
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWolla authored Apr 4, 2024
1 parent c4be758 commit 4e04201
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Type/Parser/Lexer/Token/ObjectToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnitEnum>`
? (new EnumNameToken($this->className))->traverse($stream)
: (new ClassNameToken($this->className))->traverse($stream);
}

Expand Down
2 changes: 0 additions & 2 deletions src/Type/Parser/Lexer/Token/VacantToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<UnitEnum>`
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);
}

Expand Down
6 changes: 6 additions & 0 deletions src/Utility/Reflection/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use ReflectionType;
use ReflectionUnionType;
use Reflector;
use UnitEnum;

use function array_filter;
use function array_map;
Expand Down Expand Up @@ -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
{
Expand All @@ -55,6 +58,9 @@ public static function classOrInterfaceExists(string $name): bool
&& self::class($name)->name === ltrim($name, '\\');
}

/**
* @phpstan-assert-if-true class-string<UnitEnum> $name
*/
public static function enumExists(string $name): bool
{
// @infection-ignore-all / We don't need to test the cache
Expand Down

0 comments on commit 4e04201

Please sign in to comment.