mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
UnsafeForeachArrayOfStringRule: use statically analysable function reference
this will ensure that it get automatically updated during refactors.
This commit is contained in:
parent
8da27ea0aa
commit
f1723acfd3
@ -34,6 +34,7 @@ use PHPStan\Type\StringType;
|
||||
use PHPStan\Type\Type;
|
||||
use PHPStan\Type\TypeTraverser;
|
||||
use PHPStan\Type\VerbosityLevel;
|
||||
use pocketmine\utils\Utils;
|
||||
use function sprintf;
|
||||
|
||||
/**
|
||||
@ -77,11 +78,12 @@ final class UnsafeForeachArrayOfStringRule implements Rule{
|
||||
return $type;
|
||||
});
|
||||
if($hasCastableKeyTypes && !$expectsIntKeyTypes){
|
||||
$func = \Closure::fromCallable([Utils::class, 'stringifyKeys']);
|
||||
return [
|
||||
RuleErrorBuilder::message(sprintf(
|
||||
"Unsafe foreach on array with key type %s (they might be casted to int).",
|
||||
$iterableType->getIterableKeyType()->describe(VerbosityLevel::value())
|
||||
))->tip("Use Utils::stringifyKeys() for a safe Generator-based iterator.")->build()
|
||||
))->tip(sprintf("Use %s() for a safe Generator-based iterator.", Utils::getNiceClosureName($func)))->build()
|
||||
];
|
||||
}
|
||||
return [];
|
||||
|
Loading…
x
Reference in New Issue
Block a user