Update to PHPStan 2.x

This commit is contained in:
Dylan K. Taylor
2025-01-07 22:34:43 +00:00
parent d25ec58a6f
commit 9633b7d8a7
18 changed files with 876 additions and 344 deletions

View File

@ -30,7 +30,6 @@ use PhpParser\Node\Expr\BinaryOp\NotIdentical;
use PHPStan\Analyser\Scope;
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\ObjectType;
use PHPStan\Type\Type;
use PHPStan\Type\UnionType;
use PHPStan\Type\VerbosityLevel;
@ -61,7 +60,7 @@ class DisallowEnumComparisonRule implements Rule{
$node instanceof Identical ? '===' : '!==',
$leftType->describe(VerbosityLevel::value()),
$rightType->describe(VerbosityLevel::value())
))->build()];
))->identifier('pocketmine.enum.badComparison')->build()];
}
return [];
}
@ -69,7 +68,7 @@ class DisallowEnumComparisonRule implements Rule{
private function checkForEnumTypes(Type $comparedType) : bool{
//TODO: what we really want to do here is iterate over the contained types, but there's no universal way to
//do that. This might break with other circumstances.
if($comparedType instanceof ObjectType){
if($comparedType->isObject()->yes()){
$types = [$comparedType];
}elseif($comparedType instanceof UnionType){
$types = $comparedType->getTypes();
@ -77,12 +76,14 @@ class DisallowEnumComparisonRule implements Rule{
return false;
}
foreach($types as $containedType){
if(!($containedType instanceof ObjectType)){
if(!($containedType->isObject()->yes())){
continue;
}
$class = $containedType->getClassReflection();
if($class !== null && $class->hasTraitUse(EnumTrait::class)){
return true;
$classes = $containedType->getObjectClassReflections();
foreach($classes as $class){
if($class->hasTraitUse(EnumTrait::class)){
return true;
}
}
}
return false;