mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 04:38:35 +00:00
Utils: added crutch assumeNotFalse()
this can be used to get PHPStan to shut up about stuff that will never return false in normal contexts. It's more fine-grained than @phpstan-ignore-line and less hassle than ignoreErrors (and works in PhpStorm too). In addition, it's easy to search for references.
This commit is contained in:
parent
45b4fa0e96
commit
c6466a6da9
@ -592,4 +592,17 @@ final class Utils{
|
|||||||
throw new \InvalidArgumentException("Text must be valid UTF-8");
|
throw new \InvalidArgumentException("Text must be valid UTF-8");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @phpstan-template TValue
|
||||||
|
* @phpstan-param TValue|false $value
|
||||||
|
* @phpstan-param string|\Closure() : string $context
|
||||||
|
* @phpstan-return TValue
|
||||||
|
*/
|
||||||
|
public static function assumeNotFalse(mixed $value, \Closure|string $context = "This should never be false") : mixed{
|
||||||
|
if($value === false){
|
||||||
|
throw new AssumptionFailedError("Assumption failure: " . (is_string($context) ? $context : $context()) . " (THIS IS A BUG)");
|
||||||
|
}
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user