*/ class DisallowEnumComparisonRule implements Rule{ public function getNodeType() : string{ return BinaryOp::class; } public function processNode(Node $node, Scope $scope) : array{ if(!($node instanceof Identical) and !($node instanceof NotIdentical)){ return []; } $result = []; foreach([$node->left, $node->right] as $n){ $type = $scope->getType($n); if(!($type instanceof ObjectType)){ continue; } $class = $type->getClassReflection(); if($class === null or !$class->hasTraitUse(EnumTrait::class)){ continue; } $result[] = RuleErrorBuilder::message(sprintf( 'Strict comparison using %s involving enum %s is not reliable.', $node instanceof Identical ? '===' : '!==', $type->describe(VerbosityLevel::value()) ))->build(); } return $result; } }