diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 2c3e0d16c3..d1a31cf0bf 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1773,6 +1773,12 @@ parameters: count: 2 path: src/Type/UnionTypeHelper.php + - + rawMessage: 'Doing instanceof PHPStan\Type\Enum\EnumCaseObjectType is error-prone and deprecated. Use Type::getEnumCases() instead.' + identifier: phpstanApi.instanceofType + count: 2 + path: src/Type/UnionTypeHelper.php + - rawMessage: 'Doing instanceof PHPStan\Type\IntegerType is error-prone and deprecated. Use Type::isInteger() instead.' identifier: phpstanApi.instanceofType diff --git a/src/Type/UnionTypeHelper.php b/src/Type/UnionTypeHelper.php index ba9eba259e..02fa454dcb 100644 --- a/src/Type/UnionTypeHelper.php +++ b/src/Type/UnionTypeHelper.php @@ -7,6 +7,7 @@ use PHPStan\Type\Constant\ConstantFloatType; use PHPStan\Type\Constant\ConstantIntegerType; use PHPStan\Type\Constant\ConstantStringType; +use PHPStan\Type\Enum\EnumCaseObjectType; use function count; use function strcasecmp; use function usort; @@ -96,6 +97,20 @@ public static function sortTypes(array $types): array return self::compareStrings($a->getValue(), $b->getValue()); } + if ($a instanceof EnumCaseObjectType && $b instanceof EnumCaseObjectType) { + return self::compareStrings( + $a->getClassName() . '::' . $a->getEnumCaseName(), + $b->getClassName() . '::' . $b->getEnumCaseName(), + ); + } + + if ( + ($a instanceof CallableType || $a instanceof ClosureType) + && ($b instanceof CallableType || $b instanceof ClosureType) + ) { + return self::compareStrings($a->describe(VerbosityLevel::value()), $b->describe(VerbosityLevel::value())); + } + if ($a->isConstantArray()->yes() && $b->isConstantArray()->yes()) { if ($a->isIterableAtLeastOnce()->no()) { if ($b->isIterableAtLeastOnce()->no()) { @@ -110,13 +125,6 @@ public static function sortTypes(array $types): array return self::compareStrings($a->describe(VerbosityLevel::value()), $b->describe(VerbosityLevel::value())); } - if ( - ($a instanceof CallableType || $a instanceof ClosureType) - && ($b instanceof CallableType || $b instanceof ClosureType) - ) { - return self::compareStrings($a->describe(VerbosityLevel::value()), $b->describe(VerbosityLevel::value())); - } - if ($a->isString()->yes() && $b->isString()->yes()) { return self::compareStrings($a->describe(VerbosityLevel::precise()), $b->describe(VerbosityLevel::precise())); }