Skip to content

Commit f319d82

Browse files
committed
resolve feedback
This (mostly) resolves https://github.com/phpstan/phpstan-src/pull/3613/files#r1835477700 in that the error reappears, but loses the lowercase-string portion of the error string.
1 parent e511b0e commit f319d82

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/Reflection/InitializerExprTypeResolver.php

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,13 +482,7 @@ public function resolveConcatType(Type $left, Type $right): Type
482482
$accessoryTypes[] = new AccessoryLiteralStringType();
483483
}
484484

485-
if ($leftStringType->isLowercaseString()->and($rightStringType->isLowercaseString())->yes()) {
486-
$accessoryTypes[] = new AccessoryLowercaseStringType();
487-
}
488-
489-
if ($leftStringType->isUppercaseString()->and($rightStringType->isUppercaseString())->yes()) {
490-
$accessoryTypes[] = new AccessoryUppercaseStringType();
491-
}
485+
$this->appendAccessoryCasedStringTypes($leftStringType, $rightStringType, $accessoryTypes);
492486

493487
$leftNumericStringNonEmpty = TypeCombinator::remove($leftStringType, new ConstantStringType(''));
494488
if ($leftNumericStringNonEmpty->isNumericString()->yes()) {
@@ -524,6 +518,26 @@ public function resolveConcatType(Type $left, Type $right): Type
524518
return new StringType();
525519
}
526520

521+
protected function appendAccessoryCasedStringTypes($leftStringType, $rightStringType, array &$accessoryTypes): void
522+
{
523+
$lower = $leftStringType->isLowercaseString()->and($rightStringType->isLowercaseString())->yes();
524+
$upper = $leftStringType->isUppercaseString()->and($rightStringType->isUppercaseString())->yes();
525+
526+
if ($lower && $upper) {
527+
return;
528+
}
529+
530+
if ($lower) {
531+
$accessoryTypes[] = new AccessoryLowercaseStringType();
532+
return;
533+
}
534+
535+
if ($upper) {
536+
$accessoryTypes[] = new AccessoryUppercaseStringType();
537+
return;
538+
}
539+
}
540+
527541
/**
528542
* @param callable(Expr): Type $getTypeCallback
529543
*/

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,10 @@ public function testArrayUdiffCallback(): void
635635
'Parameter #3 $data_comp_func of function array_udiff expects callable(1|2|3|4|5|6, 1|2|3|4|5|6): int, Closure(string, string): string given.',
636636
6,
637637
],
638+
[
639+
'Parameter #3 $data_comp_func of function array_udiff expects callable(1|2|3|4|5|6, 1|2|3|4|5|6): int, Closure(int, int): (literal-string&non-falsy-string&numeric-string) given.',
640+
14,
641+
],
638642
[
639643
'Parameter #1 $arr1 of function array_udiff expects array<string>, null given.',
640644
20,

0 commit comments

Comments
 (0)