Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 15 additions & 7 deletions src/Type/UnionTypeHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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()));
}
Expand Down
Loading