Skip to content

Commit fb81427

Browse files
committed
Support new PHP8.4 mb_lcfirst, mb_ucfirst function variants
1 parent 93d85c4 commit fb81427

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/Analyser/TypeSpecifier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,9 +1017,9 @@ private function specifyTypesForConstantStringBinaryExpression(
10171017
&& $exprNode instanceof FuncCall
10181018
&& $exprNode->name instanceof Name
10191019
&& in_array(strtolower($exprNode->name->toString()), [
1020-
'substr', 'strstr', 'stristr', 'strchr', 'strrchr', 'strtolower', 'strtoupper',
1021-
'mb_substr', 'mb_strstr', 'mb_stristr', 'mb_strchr', 'mb_strrchr', 'mb_strtolower', 'mb_strtoupper',
1022-
'ucfirst', 'lcfirst', 'ucwords', 'mb_convert_case', 'mb_convert_kana',
1020+
'substr', 'strstr', 'stristr', 'strchr', 'strrchr', 'strtolower', 'strtoupper', 'ucfirst', 'lcfirst',
1021+
'mb_substr', 'mb_strstr', 'mb_stristr', 'mb_strchr', 'mb_strrchr', 'mb_strtolower', 'mb_strtoupper', 'mb_ucfirst', 'mb_lcfirst',
1022+
'ucwords', 'mb_convert_case', 'mb_convert_kana',
10231023
], true)
10241024
&& isset($exprNode->getArgs()[0])
10251025
&& $constantType->getValue() !== ''

src/Type/Php/StrCaseFunctionsReturnTypeExtension.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class StrCaseFunctionsReturnTypeExtension implements DynamicFunctionReturnTypeEx
3434
'mb_strtolower' => 1,
3535
'lcfirst' => 1,
3636
'ucfirst' => 1,
37+
'mb_lcfirst' => 1,
38+
'mb_ucfirst' => 1,
3739
'ucwords' => 1,
3840
'mb_convert_case' => 2,
3941
'mb_convert_kana' => 1,

tests/PHPStan/Analyser/data/str-casing.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public function bar($numericS, $nonE, $literal, $edgeUnion, $caseMode, $kanaMode
2525
assertType("'ABC'", mb_strtoupper('Abc'));
2626
assertType("'aBC'", lcfirst('ABC'));
2727
assertType("'Abc'", ucfirst('abc'));
28+
assertType("'aBC'", mb_lcfirst('ABC'));
29+
assertType("'Abc'", mb_ucfirst('abc'));
2830
assertType("'Hello World'", ucwords('hello world'));
2931
assertType("'Hello|World'", ucwords('hello|world', "|"));
3032
assertType("'ČESKÁ REPUBLIKA'", mb_convert_case('Česká republika', MB_CASE_UPPER));
@@ -43,6 +45,8 @@ public function bar($numericS, $nonE, $literal, $edgeUnion, $caseMode, $kanaMode
4345
assertType("numeric-string", mb_strtoupper($numericS));
4446
assertType("numeric-string", lcfirst($numericS));
4547
assertType("numeric-string", ucfirst($numericS));
48+
assertType("numeric-string", mb_lcfirst($numericS));
49+
assertType("numeric-string", mb_ucfirst($numericS));
4650
assertType("numeric-string", ucwords($numericS));
4751
assertType("numeric-string", mb_convert_case($numericS, MB_CASE_UPPER));
4852
assertType("numeric-string", mb_convert_case($numericS, MB_CASE_LOWER));
@@ -56,6 +60,8 @@ public function bar($numericS, $nonE, $literal, $edgeUnion, $caseMode, $kanaMode
5660
assertType("non-empty-string", mb_strtoupper($nonE));
5761
assertType("non-empty-string", lcfirst($nonE));
5862
assertType("non-empty-string", ucfirst($nonE));
63+
assertType("non-empty-string", mb_lcfirst($nonE));
64+
assertType("non-empty-string", mb_ucfirst($nonE));
5965
assertType("non-empty-string", ucwords($nonE));
6066
assertType("non-empty-string", mb_convert_case($nonE, MB_CASE_UPPER));
6167
assertType("non-empty-string", mb_convert_case($nonE, MB_CASE_LOWER));
@@ -69,6 +75,8 @@ public function bar($numericS, $nonE, $literal, $edgeUnion, $caseMode, $kanaMode
6975
assertType("string", mb_strtoupper($literal));
7076
assertType("string", lcfirst($literal));
7177
assertType("string", ucfirst($literal));
78+
assertType("string", mb_lcfirst($literal));
79+
assertType("string", mb_ucfirst($literal));
7280
assertType("string", ucwords($literal));
7381
assertType("string", mb_convert_case($literal, MB_CASE_UPPER));
7482
assertType("string", mb_convert_case($literal, MB_CASE_LOWER));

0 commit comments

Comments
 (0)