2121class ReplaceFunctionsDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension
2222{
2323
24- /** @var array<string, int> */
25- private array $ functionsSubjectPosition = [
24+ private const FUNCTIONS_SUBJECT_POSITION = [
2625 'preg_replace ' => 2 ,
2726 'preg_replace_callback ' => 2 ,
2827 'preg_replace_callback_array ' => 1 ,
@@ -32,8 +31,7 @@ class ReplaceFunctionsDynamicReturnTypeExtension implements DynamicFunctionRetur
3231 'strtr ' => 0 ,
3332 ];
3433
35- /** @var array<string, int> */
36- private array $ functionsReplacePosition = [
34+ private const FUNCTIONS_REPLACE_POSITION = [
3735 'preg_replace ' => 1 ,
3836 'str_replace ' => 1 ,
3937 'str_ireplace ' => 1 ,
@@ -43,7 +41,7 @@ class ReplaceFunctionsDynamicReturnTypeExtension implements DynamicFunctionRetur
4341
4442 public function isFunctionSupported (FunctionReflection $ functionReflection ): bool
4543 {
46- return array_key_exists ($ functionReflection ->getName (), $ this -> functionsSubjectPosition );
44+ return array_key_exists ($ functionReflection ->getName (), self :: FUNCTIONS_SUBJECT_POSITION );
4745 }
4846
4947 public function getTypeFromFunctionCall (
@@ -75,7 +73,7 @@ private function getPreliminarilyResolvedTypeFromFunctionCall(
7573 Scope $ scope ,
7674 ): Type
7775 {
78- $ argumentPosition = $ this -> functionsSubjectPosition [$ functionReflection ->getName ()];
76+ $ argumentPosition = self :: FUNCTIONS_SUBJECT_POSITION [$ functionReflection ->getName ()];
7977 $ defaultReturnType = ParametersAcceptorSelector::selectFromArgs (
8078 $ scope ,
8179 $ functionCall ->getArgs (),
@@ -91,8 +89,8 @@ private function getPreliminarilyResolvedTypeFromFunctionCall(
9189 return TypeUtils::toBenevolentUnion ($ defaultReturnType );
9290 }
9391
94- if ($ subjectArgumentType ->isNonEmptyString ()->yes () && array_key_exists ($ functionReflection ->getName (), $ this -> functionsReplacePosition )) {
95- $ replaceArgumentPosition = $ this -> functionsReplacePosition [$ functionReflection ->getName ()];
92+ if ($ subjectArgumentType ->isNonEmptyString ()->yes () && array_key_exists ($ functionReflection ->getName (), self :: FUNCTIONS_REPLACE_POSITION )) {
93+ $ replaceArgumentPosition = self :: FUNCTIONS_REPLACE_POSITION [$ functionReflection ->getName ()];
9694
9795 if (count ($ functionCall ->getArgs ()) > $ replaceArgumentPosition ) {
9896 $ replaceArgumentType = $ scope ->getType ($ functionCall ->getArgs ()[$ replaceArgumentPosition ]->value );
0 commit comments