Skip to content
Merged
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
81 changes: 39 additions & 42 deletions src/Type/TypeCombinator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use function array_values;
use function count;
use function get_class;
use function in_array;
use function is_int;
use function sprintf;
use function usort;
Expand Down Expand Up @@ -494,54 +495,50 @@
if (
$a instanceof ConstantStringType
) {
$description = $b->describe(VerbosityLevel::value());
Copy link
Copy Markdown
Contributor Author

@staabm staabm Jan 17, 2026

Choose a reason for hiding this comment

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

describe $b only when $a == ''.

before we described $b no matter which constant-value $a had

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, new IntersectionType([
new StringType(),
new AccessoryNonEmptyStringType(),
...self::getAccessoryCaseStringTypes($b),
])];
if ($a->getValue() === '') {
$description = $b->describe(VerbosityLevel::value());
if (in_array($description, ['non-empty-string', 'non-falsy-string'], true)) {
return [null, self::intersect(
new StringType(),
...self::getAccessoryCaseStringTypes($b),
)];
}
}

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

if (
$b instanceof ConstantStringType
) {
$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 [new IntersectionType([
new StringType(),
new AccessoryNonEmptyStringType(),
...self::getAccessoryCaseStringTypes($a),
]), null];
if ($b->getValue() === '') {
$description = $a->describe(VerbosityLevel::value());
if (in_array($description, ['non-empty-string', 'non-falsy-string'], true)) {
return [self::intersect(
new StringType(),
...self::getAccessoryCaseStringTypes($a),
), null];
}
}

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

Expand Down Expand Up @@ -1101,7 +1098,7 @@
unset($arraysToProcess[$i]);
continue 2;
}
}

Check failure on line 1101 in src/Type/TypeCombinator.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest, 0)

Parameter #1 $array (non-empty-list<PHPStan\Type\Type>) of array_values is already a list, call has no effect.
}

return array_merge($newArrays, $arraysToProcess);
Expand Down
Loading