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
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -1710,7 +1710,7 @@ parameters:
-
rawMessage: 'Doing instanceof PHPStan\Type\Constant\ConstantStringType is error-prone and deprecated. Use Type::getConstantStrings() instead.'
identifier: phpstanApi.instanceofType
count: 5
count: 3
path: src/Type/TypeCombinator.php

-
Expand Down
82 changes: 44 additions & 38 deletions src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -494,50 +494,56 @@ private static function compareTypesInUnion(Type $a, Type $b): ?array

if (
$a instanceof ConstantStringType
&& $a->getValue() === ''
&& ($b->describe(VerbosityLevel::value()) === 'non-empty-string'
|| $b->describe(VerbosityLevel::value()) === 'non-falsy-string')
Comment on lines -498 to -499
Copy link
Contributor Author

@staabm staabm Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new: describe each type only once

) {
return [null, self::intersect(
new StringType(),
...self::getAccessoryCaseStringTypes($b),
)];
}

if (
$b instanceof ConstantStringType
&& $b->getValue() === ''
&& ($a->describe(VerbosityLevel::value()) === 'non-empty-string'
|| $a->describe(VerbosityLevel::value()) === 'non-falsy-string')
) {
return [self::intersect(
new StringType(),
...self::getAccessoryCaseStringTypes($a),
), null];
}

if (
$a instanceof ConstantStringType
&& $a->getValue() === '0'
&& $b->describe(VerbosityLevel::value()) === 'non-falsy-string'
) {
return [null, self::intersect(
new StringType(),
new AccessoryNonEmptyStringType(),
...self::getAccessoryCaseStringTypes($b),
)];
$description = $b->describe(VerbosityLevel::value());
if (
$a->getValue() === ''
&& ($description === 'non-empty-string'
|| $description === 'non-falsy-string')
) {
return [null, self::intersect(
new StringType(),
...self::getAccessoryCaseStringTypes($b),
)];
}

if (
$a->getValue() === '0'
&& $description === 'non-falsy-string'
) {
return [null, self::intersect(
new StringType(),
new AccessoryNonEmptyStringType(),
...self::getAccessoryCaseStringTypes($b),
)];
}
}

if (
$b instanceof ConstantStringType
&& $b->getValue() === '0'
&& $a->describe(VerbosityLevel::value()) === 'non-falsy-string'
) {
return [self::intersect(
new StringType(),
new AccessoryNonEmptyStringType(),
...self::getAccessoryCaseStringTypes($a),
), null];
$description = $a->describe(VerbosityLevel::value());
if (
$b->getValue() === ''
&& ($description === 'non-empty-string'
|| $description === 'non-falsy-string')
) {
return [self::intersect(
new StringType(),
...self::getAccessoryCaseStringTypes($a),
), null];
}

if (
$b->getValue() === '0'
&& $description === 'non-falsy-string'
) {
return [self::intersect(
new StringType(),
new AccessoryNonEmptyStringType(),
...self::getAccessoryCaseStringTypes($a),
), null];
}
}

return null;
Expand Down
Loading