Skip to content

Commit

Permalink
More precise string-casing functions
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Jan 7, 2025
1 parent e1f852f commit 9cbd5f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Type/Php/StrCaseFunctionsReturnTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,19 @@ public function getTypeFromFunctionCall(
}

$accessoryTypes = [];
if ($forceLowercase || ($keepLowercase && $argType->isLowercaseString()->yes())) {
$argStringType = $argType->toString();
if ($forceLowercase || ($keepLowercase && $argStringType->isLowercaseString()->yes())) {
$accessoryTypes[] = new AccessoryLowercaseStringType();
}
if ($forceUppercase || ($keepUppercase && $argType->isUppercaseString()->yes())) {
if ($forceUppercase || ($keepUppercase && $argStringType->isUppercaseString()->yes())) {
$accessoryTypes[] = new AccessoryUppercaseStringType();
}

if ($argType->isNumericString()->yes()) {
if ($argStringType->isNumericString()->yes()) {
$accessoryTypes[] = new AccessoryNumericStringType();
} elseif ($argType->isNonFalsyString()->yes()) {
} elseif ($argStringType->isNonFalsyString()->yes()) {
$accessoryTypes[] = new AccessoryNonFalsyStringType();
} elseif ($argType->isNonEmptyString()->yes()) {
} elseif ($argStringType->isNonEmptyString()->yes()) {
$accessoryTypes[] = new AccessoryNonEmptyStringType();
}

Expand Down
1 change: 1 addition & 0 deletions tests/PHPStan/Analyser/nsrt/non-falsy-string.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function stringFunctions(string $s, $nonFalsey, $arrayOfNonFalsey, $nonEmptyArra
assertType('non-falsy-string', escapeshellarg($nonFalsey));
assertType('non-falsy-string', escapeshellcmd($nonFalsey));

assertType('non-falsy-string&uppercase-string', strtoupper($s ?: 1));
assertType('non-falsy-string&uppercase-string', strtoupper($nonFalsey));
assertType('lowercase-string&non-falsy-string', strtolower($nonFalsey));
assertType('non-falsy-string&uppercase-string', mb_strtoupper($nonFalsey));
Expand Down

0 comments on commit 9cbd5f8

Please sign in to comment.