diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 581bf41ec..296c023d6 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -10,7 +10,6 @@ includes: - vendor/phpstan/phpstan-strict-rules/rules.neon rules: - - pocketmine\phpstan\rules\DisallowEnumComparisonRule - pocketmine\phpstan\rules\DisallowForeachByReferenceRule - pocketmine\phpstan\rules\UnsafeForeachArrayOfStringRule # - pocketmine\phpstan\rules\ThreadedSupportedTypesRule diff --git a/src/utils/EnumTrait.php b/src/utils/EnumTrait.php deleted file mode 100644 index e03ec1f06..000000000 --- a/src/utils/EnumTrait.php +++ /dev/null @@ -1,108 +0,0 @@ -name(), $member); - } - - protected static function registerAll(self ...$members) : void{ - foreach($members as $member){ - self::register($member); - } - } - - /** - * Returns all members of the enum. - * This is overridden to change the return typehint. - * - * @return self[] - * @phpstan-return array - */ - public static function getAll() : array{ - //phpstan doesn't support generic traits yet :( - /** @var self[] $result */ - $result = self::_registryGetAll(); - return $result; - } - - /** @var int|null */ - private static $nextId = null; - - /** @var string */ - private $enumName; - /** @var int */ - private $runtimeId; - - /** - * @throws \InvalidArgumentException - */ - private function __construct(string $enumName){ - self::verifyName($enumName); - $this->enumName = $enumName; - if(self::$nextId === null){ - self::$nextId = Process::pid(); //this provides enough base entropy to prevent hardcoding - } - $this->runtimeId = self::$nextId++; - } - - public function name() : string{ - return $this->enumName; - } - - /** - * Returns a runtime-only identifier for this enum member. This will be different with each run, so don't try to - * hardcode it. - * This can be useful for switches or array indexing. - */ - public function id() : int{ - return $this->runtimeId; - } - - /** - * Returns whether the two objects are equivalent. - */ - public function equals(self $other) : bool{ - return $this->enumName === $other->enumName; - } -} diff --git a/tests/phpstan/rules/DisallowEnumComparisonRule.php b/tests/phpstan/rules/DisallowEnumComparisonRule.php deleted file mode 100644 index fc5377173..000000000 --- a/tests/phpstan/rules/DisallowEnumComparisonRule.php +++ /dev/null @@ -1,90 +0,0 @@ - - */ -class DisallowEnumComparisonRule implements Rule{ - - public function getNodeType() : string{ - return BinaryOp::class; - } - - public function processNode(Node $node, Scope $scope) : array{ - if(!($node instanceof Identical) && !($node instanceof NotIdentical)){ - return []; - } - - $leftType = $scope->getType($node->left); - $rightType = $scope->getType($node->right); - $leftEnum = $this->checkForEnumTypes($leftType); - $rightEnum = $this->checkForEnumTypes($rightType); - if($leftEnum && $rightEnum){ - return [RuleErrorBuilder::message(sprintf( - 'Strict comparison using %s involving enum types %s and %s is not reliable.', - $node instanceof Identical ? '===' : '!==', - $leftType->describe(VerbosityLevel::value()), - $rightType->describe(VerbosityLevel::value()) - ))->build()]; - } - return []; - } - - 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){ - $types = [$comparedType]; - }elseif($comparedType instanceof UnionType){ - $types = $comparedType->getTypes(); - }else{ - return false; - } - foreach($types as $containedType){ - if(!($containedType instanceof ObjectType)){ - continue; - } - $class = $containedType->getClassReflection(); - if($class !== null && $class->hasTraitUse(EnumTrait::class)){ - return true; - } - } - return false; - } -} diff --git a/tests/phpunit/utils/EnumTraitTest.php b/tests/phpunit/utils/EnumTraitTest.php deleted file mode 100644 index 4108847e9..000000000 --- a/tests/phpunit/utils/EnumTraitTest.php +++ /dev/null @@ -1,38 +0,0 @@ -