diff --git a/src/Type/Php/ArgumentBasedFunctionReturnTypeExtension.php b/src/Type/Php/ArgumentBasedFunctionReturnTypeExtension.php index a4a2b94384..30cc350855 100644 --- a/src/Type/Php/ArgumentBasedFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArgumentBasedFunctionReturnTypeExtension.php @@ -50,11 +50,12 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, } $argumentPosition = self::FUNCTION_NAMES[$functionReflection->getName()]; - if (!isset($functionCall->getArgs()[$argumentPosition])) { + $args = $functionCall->getArgs(); + if (!isset($args[$argumentPosition])) { return null; } - $argument = $functionCall->getArgs()[$argumentPosition]; + $argument = $args[$argumentPosition]; $argumentType = $scope->getType($argument->value); $argumentKeyType = $argumentType->getIterableKeyType(); $argumentValueType = $argumentType->getIterableValueType(); diff --git a/src/Type/Php/ArrayChangeKeyCaseFunctionReturnTypeExtension.php b/src/Type/Php/ArrayChangeKeyCaseFunctionReturnTypeExtension.php index 4b0d81157b..070e61558c 100644 --- a/src/Type/Php/ArrayChangeKeyCaseFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayChangeKeyCaseFunctionReturnTypeExtension.php @@ -42,15 +42,16 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } - $arrayType = $scope->getType($functionCall->getArgs()[0]->value); - if (!isset($functionCall->getArgs()[1])) { + $arrayType = $scope->getType($args[0]->value); + if (!isset($args[1])) { $case = CASE_LOWER; } else { - $caseType = $scope->getType($functionCall->getArgs()[1]->value); + $caseType = $scope->getType($args[1]->value); $scalarValues = $caseType->getConstantScalarValues(); if (count($scalarValues) === 1) { $case = (int) $scalarValues[0]; diff --git a/src/Type/Php/ArrayChunkFunctionReturnTypeExtension.php b/src/Type/Php/ArrayChunkFunctionReturnTypeExtension.php index 1028ae2fa1..cfd69286ec 100644 --- a/src/Type/Php/ArrayChunkFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayChunkFunctionReturnTypeExtension.php @@ -30,22 +30,23 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 2) { + $args = $functionCall->getArgs(); + if (count($args) < 2) { return null; } - $arrayType = $scope->getType($functionCall->getArgs()[0]->value); + $arrayType = $scope->getType($args[0]->value); if ($arrayType->isArray()->no()) { return $this->phpVersion->arrayFunctionsReturnNullWithNonArray() ? new NullType() : new NeverType(); } - $lengthType = $scope->getType($functionCall->getArgs()[1]->value); + $lengthType = $scope->getType($args[1]->value); $negativeOrZero = IntegerRangeType::fromInterval(null, 0); if ($negativeOrZero->isSuperTypeOf($lengthType)->yes()) { return $this->phpVersion->throwsValueErrorForInternalFunctions() ? new NeverType() : new NullType(); } - $preserveKeysType = isset($functionCall->getArgs()[2]) ? $scope->getType($functionCall->getArgs()[2]->value) : new ConstantBooleanType(false); + $preserveKeysType = isset($args[2]) ? $scope->getType($args[2]->value) : new ConstantBooleanType(false); return $arrayType->chunkArray($lengthType, $preserveKeysType->isTrue()); } diff --git a/src/Type/Php/ArrayColumnFunctionReturnTypeExtension.php b/src/Type/Php/ArrayColumnFunctionReturnTypeExtension.php index 4fec6cfe3e..5e69171ee6 100644 --- a/src/Type/Php/ArrayColumnFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayColumnFunctionReturnTypeExtension.php @@ -28,14 +28,15 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - $numArgs = count($functionCall->getArgs()); + $args = $functionCall->getArgs(); + $numArgs = count($args); if ($numArgs < 2) { return null; } - $arrayType = $scope->getType($functionCall->getArgs()[0]->value); - $columnType = $scope->getType($functionCall->getArgs()[1]->value); - $indexType = $numArgs >= 3 ? $scope->getType($functionCall->getArgs()[2]->value) : new NullType(); + $arrayType = $scope->getType($args[0]->value); + $columnType = $scope->getType($args[1]->value); + $indexType = $numArgs >= 3 ? $scope->getType($args[2]->value) : new NullType(); $constantArrayTypes = $arrayType->getConstantArrays(); if (count($constantArrayTypes) === 1) { diff --git a/src/Type/Php/ArrayCombineFunctionReturnTypeExtension.php b/src/Type/Php/ArrayCombineFunctionReturnTypeExtension.php index a9b9c0e042..d32c5d5d77 100644 --- a/src/Type/Php/ArrayCombineFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayCombineFunctionReturnTypeExtension.php @@ -40,12 +40,13 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 2) { + $args = $functionCall->getArgs(); + if (count($args) < 2) { return null; } - $firstArg = $functionCall->getArgs()[0]->value; - $secondArg = $functionCall->getArgs()[1]->value; + $firstArg = $args[0]->value; + $secondArg = $args[1]->value; $keysParamType = $scope->getType($firstArg); $valuesParamType = $scope->getType($secondArg); diff --git a/src/Type/Php/ArrayCurrentDynamicReturnTypeExtension.php b/src/Type/Php/ArrayCurrentDynamicReturnTypeExtension.php index 2514aad8f8..8c2bbd94c8 100644 --- a/src/Type/Php/ArrayCurrentDynamicReturnTypeExtension.php +++ b/src/Type/Php/ArrayCurrentDynamicReturnTypeExtension.php @@ -22,11 +22,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } - $argType = $scope->getType($functionCall->getArgs()[0]->value); + $argType = $scope->getType($args[0]->value); $iterableAtLeastOnce = $argType->isIterableAtLeastOnce(); if ($iterableAtLeastOnce->no()) { return new ConstantBooleanType(false); diff --git a/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php b/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php index 63cf6d9cf4..cf445cf0fe 100644 --- a/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayFillFunctionReturnTypeExtension.php @@ -38,11 +38,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 3) { + $args = $functionCall->getArgs(); + if (count($args) < 3) { return null; } - $numberType = $scope->getType($functionCall->getArgs()[1]->value); + $numberType = $scope->getType($args[1]->value); $isValidNumberType = IntegerRangeType::fromInterval(0, null)->isSuperTypeOf($numberType); // check against negative-int, which is not allowed @@ -53,8 +54,8 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, return new ConstantBooleanType(false); } - $startIndexType = $scope->getType($functionCall->getArgs()[0]->value); - $valueType = $scope->getType($functionCall->getArgs()[2]->value); + $startIndexType = $scope->getType($args[0]->value); + $valueType = $scope->getType($args[2]->value); if ( $startIndexType instanceof ConstantIntegerType diff --git a/src/Type/Php/ArrayFillKeysFunctionReturnTypeExtension.php b/src/Type/Php/ArrayFillKeysFunctionReturnTypeExtension.php index bf05500cba..c961c45362 100644 --- a/src/Type/Php/ArrayFillKeysFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayFillKeysFunctionReturnTypeExtension.php @@ -28,16 +28,17 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 2) { + $args = $functionCall->getArgs(); + if (count($args) < 2) { return null; } - $keysType = $scope->getType($functionCall->getArgs()[0]->value); + $keysType = $scope->getType($args[0]->value); if ($keysType->isArray()->no()) { return $this->phpVersion->arrayFunctionsReturnNullWithNonArray() ? new NullType() : new NeverType(); } - return $keysType->fillKeysArray($scope->getType($functionCall->getArgs()[1]->value)); + return $keysType->fillKeysArray($scope->getType($args[1]->value)); } } diff --git a/src/Type/Php/ArrayFilterFunctionReturnTypeExtension.php b/src/Type/Php/ArrayFilterFunctionReturnTypeExtension.php index 6979c23759..28aa0e8da8 100644 --- a/src/Type/Php/ArrayFilterFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayFilterFunctionReturnTypeExtension.php @@ -24,9 +24,10 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { - $arrayArg = $functionCall->getArgs()[0]->value ?? null; - $callbackArg = $functionCall->getArgs()[1]->value ?? null; - $flagArg = $functionCall->getArgs()[2]->value ?? null; + $args = $functionCall->getArgs(); + $arrayArg = $args[0]->value ?? null; + $callbackArg = $args[1]->value ?? null; + $flagArg = $args[2]->value ?? null; return $this->arrayFilterFunctionReturnTypeHelper->getType($scope, $arrayArg, $callbackArg, $flagArg); } diff --git a/src/Type/Php/ArrayFindFunctionReturnTypeExtension.php b/src/Type/Php/ArrayFindFunctionReturnTypeExtension.php index 3cf1f7c9b7..93655fa68c 100644 --- a/src/Type/Php/ArrayFindFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayFindFunctionReturnTypeExtension.php @@ -27,17 +27,18 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 2) { + $args = $functionCall->getArgs(); + if (count($args) < 2) { return null; } - $arrayType = $scope->getType($functionCall->getArgs()[0]->value); + $arrayType = $scope->getType($args[0]->value); if (count($arrayType->getArrays()) < 1) { return null; } - $arrayArg = $functionCall->getArgs()[0]->value ?? null; - $callbackArg = $functionCall->getArgs()[1]->value ?? null; + $arrayArg = $args[0]->value ?? null; + $callbackArg = $args[1]->value ?? null; $resultTypes = $this->arrayFilterFunctionReturnTypeHelper->getType($scope, $arrayArg, $callbackArg, null); $resultType = TypeCombinator::union(...array_map(static fn ($type) => $type->getIterableValueType(), $resultTypes->getArrays())); diff --git a/src/Type/Php/ArrayFindKeyFunctionReturnTypeExtension.php b/src/Type/Php/ArrayFindKeyFunctionReturnTypeExtension.php index 58faf9d8bf..9a02e63d99 100644 --- a/src/Type/Php/ArrayFindKeyFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayFindKeyFunctionReturnTypeExtension.php @@ -23,11 +23,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 2) { + $args = $functionCall->getArgs(); + if (count($args) < 2) { return null; } - $arrayType = $scope->getType($functionCall->getArgs()[0]->value); + $arrayType = $scope->getType($args[0]->value); if (count($arrayType->getArrays()) < 1) { return null; } diff --git a/src/Type/Php/ArrayFlipFunctionReturnTypeExtension.php b/src/Type/Php/ArrayFlipFunctionReturnTypeExtension.php index 3e82909d22..f21e9dc294 100644 --- a/src/Type/Php/ArrayFlipFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayFlipFunctionReturnTypeExtension.php @@ -30,11 +30,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) !== 1) { + $args = $functionCall->getArgs(); + if (count($args) !== 1) { return null; } - $arrayType = $scope->getType($functionCall->getArgs()[0]->value); + $arrayType = $scope->getType($args[0]->value); if ($arrayType->isArray()->no()) { return $this->phpVersion->arrayFunctionsReturnNullWithNonArray() ? new NullType() : new NeverType(); } diff --git a/src/Type/Php/ArrayKeyDynamicReturnTypeExtension.php b/src/Type/Php/ArrayKeyDynamicReturnTypeExtension.php index 2844706529..3499b54052 100644 --- a/src/Type/Php/ArrayKeyDynamicReturnTypeExtension.php +++ b/src/Type/Php/ArrayKeyDynamicReturnTypeExtension.php @@ -22,11 +22,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } - $argType = $scope->getType($functionCall->getArgs()[0]->value); + $argType = $scope->getType($args[0]->value); $iterableAtLeastOnce = $argType->isIterableAtLeastOnce(); if ($iterableAtLeastOnce->no()) { return new NullType(); diff --git a/src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php b/src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php index b03ae852f2..ae9afb3005 100644 --- a/src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/ArrayKeyExistsFunctionTypeSpecifyingExtension.php @@ -61,11 +61,12 @@ public function specifyTypes( TypeSpecifierContext $context, ): SpecifiedTypes { - if (count($node->getArgs()) < 2) { + $args = $node->getArgs(); + if (count($args) < 2) { return new SpecifiedTypes(); } - $key = $node->getArgs()[0]->value; - $array = $node->getArgs()[1]->value; + $key = $args[0]->value; + $array = $args[1]->value; $keyType = $scope->getType($key)->toArrayKey(); $arrayType = $scope->getType($array); diff --git a/src/Type/Php/ArrayMapFunctionReturnTypeExtension.php b/src/Type/Php/ArrayMapFunctionReturnTypeExtension.php index 8da098e09c..78699643bd 100644 --- a/src/Type/Php/ArrayMapFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayMapFunctionReturnTypeExtension.php @@ -38,13 +38,14 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - $numArgs = count($functionCall->getArgs()); + $args = $functionCall->getArgs(); + $numArgs = count($args); if ($numArgs < 2) { return null; } - $singleArrayArgument = !isset($functionCall->getArgs()[2]); - $callback = $functionCall->getArgs()[0]->value; + $singleArrayArgument = !isset($args[2]); + $callback = $args[0]->value; $callableType = $scope->getType($callback); $callableIsNull = $callableType->isNull()->yes(); @@ -53,7 +54,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $callback, array_map( static fn (Node\Arg $arg) => new Node\Arg(new TypeExpr($scope->getType($arg->value)->getIterableValueType())), - array_slice($functionCall->getArgs(), 1), + array_slice($args, 1), ), )); } elseif ($callableIsNull) { @@ -61,7 +62,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $argTypes = []; $areAllSameSize = true; $expectedSize = null; - foreach (array_slice($functionCall->getArgs(), 1) as $index => $arg) { + foreach (array_slice($args, 1) as $index => $arg) { $argTypes[$index] = $argType = $scope->getType($arg->value); if (!$areAllSameSize || $numArgs === 2) { continue; @@ -85,9 +86,9 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, } if (!$areAllSameSize) { - $firstArr = $functionCall->getArgs()[1]->value; + $firstArr = $args[1]->value; $identities = []; - foreach (array_slice($functionCall->getArgs(), 2) as $arg) { + foreach (array_slice($args, 2) as $arg) { $identities[] = new Node\Expr\BinaryOp\Identical($firstArr, $arg->value); } @@ -117,7 +118,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $valueType = new MixedType(); } - $arrayType = $scope->getType($functionCall->getArgs()[1]->value); + $arrayType = $scope->getType($args[1]->value); if ($singleArrayArgument) { if ($callableIsNull) { diff --git a/src/Type/Php/ArrayNextDynamicReturnTypeExtension.php b/src/Type/Php/ArrayNextDynamicReturnTypeExtension.php index a0f49b4ca3..c8ced44e43 100644 --- a/src/Type/Php/ArrayNextDynamicReturnTypeExtension.php +++ b/src/Type/Php/ArrayNextDynamicReturnTypeExtension.php @@ -23,11 +23,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } - $argType = $scope->getType($functionCall->getArgs()[0]->value); + $argType = $scope->getType($args[0]->value); $iterableAtLeastOnce = $argType->isIterableAtLeastOnce(); if ($iterableAtLeastOnce->no()) { return new ConstantBooleanType(false); diff --git a/src/Type/Php/ArrayPadDynamicReturnTypeExtension.php b/src/Type/Php/ArrayPadDynamicReturnTypeExtension.php index 896034f32f..0fad843c42 100644 --- a/src/Type/Php/ArrayPadDynamicReturnTypeExtension.php +++ b/src/Type/Php/ArrayPadDynamicReturnTypeExtension.php @@ -26,19 +26,20 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[2])) { + $args = $functionCall->getArgs(); + if (!isset($args[2])) { return null; } - $arrayType = $scope->getType($functionCall->getArgs()[0]->value); - $itemType = $scope->getType($functionCall->getArgs()[2]->value); + $arrayType = $scope->getType($args[0]->value); + $itemType = $scope->getType($args[2]->value); $returnType = new ArrayType( TypeCombinator::union($arrayType->getIterableKeyType(), new IntegerType()), TypeCombinator::union($arrayType->getIterableValueType(), $itemType), ); - $lengthType = $scope->getType($functionCall->getArgs()[1]->value); + $lengthType = $scope->getType($args[1]->value); if ( $arrayType->isIterableAtLeastOnce()->yes() || $lengthType->isSuperTypeOf(new ConstantIntegerType(0))->no() diff --git a/src/Type/Php/ArrayPopFunctionReturnTypeExtension.php b/src/Type/Php/ArrayPopFunctionReturnTypeExtension.php index 5a570752ed..36ae85d431 100644 --- a/src/Type/Php/ArrayPopFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayPopFunctionReturnTypeExtension.php @@ -22,11 +22,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } - $argType = $scope->getType($functionCall->getArgs()[0]->value); + $argType = $scope->getType($args[0]->value); $iterableAtLeastOnce = $argType->isIterableAtLeastOnce(); if ($iterableAtLeastOnce->no()) { return new NullType(); diff --git a/src/Type/Php/ArrayRandFunctionReturnTypeExtension.php b/src/Type/Php/ArrayRandFunctionReturnTypeExtension.php index f61d48033e..0101817497 100644 --- a/src/Type/Php/ArrayRandFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayRandFunctionReturnTypeExtension.php @@ -28,12 +28,13 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - $argsCount = count($functionCall->getArgs()); + $args = $functionCall->getArgs(); + $argsCount = count($args); if ($argsCount < 1) { return null; } - $firstArgType = $scope->getType($functionCall->getArgs()[0]->value); + $firstArgType = $scope->getType($args[0]->value); $isInteger = $firstArgType->getIterableKeyType()->isInteger(); $isString = $firstArgType->getIterableKeyType()->isString(); @@ -49,7 +50,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, return $valueType; } - $secondArgType = $scope->getType($functionCall->getArgs()[1]->value); + $secondArgType = $scope->getType($args[1]->value); $one = new ConstantIntegerType(1); if ($one->isSuperTypeOf($secondArgType)->yes()) { diff --git a/src/Type/Php/ArrayReduceFunctionReturnTypeExtension.php b/src/Type/Php/ArrayReduceFunctionReturnTypeExtension.php index 7f955e6baa..a38f2801df 100644 --- a/src/Type/Php/ArrayReduceFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayReduceFunctionReturnTypeExtension.php @@ -25,28 +25,29 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[1])) { + $args = $functionCall->getArgs(); + if (!isset($args[1])) { return null; } - $callbackType = $scope->getType($functionCall->getArgs()[1]->value); + $callbackType = $scope->getType($args[1]->value); if ($callbackType->isCallable()->no()) { return null; } $callbackReturnType = ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->getArgs(), + $args, $callbackType->getCallableParametersAcceptors($scope), )->getReturnType(); - if (isset($functionCall->getArgs()[2])) { - $initialType = $scope->getType($functionCall->getArgs()[2]->value); + if (isset($args[2])) { + $initialType = $scope->getType($args[2]->value); } else { $initialType = new NullType(); } - $arraysType = $scope->getType($functionCall->getArgs()[0]->value); + $arraysType = $scope->getType($args[0]->value); $constantArrays = $arraysType->getConstantArrays(); if (count($constantArrays) > 0) { $onlyEmpty = TrinaryLogic::createYes(); diff --git a/src/Type/Php/ArrayReverseFunctionReturnTypeExtension.php b/src/Type/Php/ArrayReverseFunctionReturnTypeExtension.php index 0c90c7bfaa..7f4f2a754f 100644 --- a/src/Type/Php/ArrayReverseFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayReverseFunctionReturnTypeExtension.php @@ -28,16 +28,17 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } - $type = $scope->getType($functionCall->getArgs()[0]->value); + $type = $scope->getType($args[0]->value); if ($type->isArray()->no()) { return $this->phpVersion->arrayFunctionsReturnNullWithNonArray() ? new NullType() : new NeverType(); } - $preserveKeysType = isset($functionCall->getArgs()[1]) ? $scope->getType($functionCall->getArgs()[1]->value) : new ConstantBooleanType(false); + $preserveKeysType = isset($args[1]) ? $scope->getType($args[1]->value) : new ConstantBooleanType(false); return $type->reverseArray($preserveKeysType->isTrue()); } diff --git a/src/Type/Php/ArraySearchFunctionDynamicReturnTypeExtension.php b/src/Type/Php/ArraySearchFunctionDynamicReturnTypeExtension.php index b392e91340..87810f8fb0 100644 --- a/src/Type/Php/ArraySearchFunctionDynamicReturnTypeExtension.php +++ b/src/Type/Php/ArraySearchFunctionDynamicReturnTypeExtension.php @@ -29,12 +29,13 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - $argsCount = count($functionCall->getArgs()); + $args = $functionCall->getArgs(); + $argsCount = count($args); if ($argsCount < 2) { return null; } - $haystackArgType = $scope->getType($functionCall->getArgs()[1]->value); + $haystackArgType = $scope->getType($args[1]->value); if ($haystackArgType->isArray()->no()) { return $this->phpVersion->arrayFunctionsReturnNullWithNonArray() ? new NullType() : new NeverType(); } @@ -42,10 +43,10 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, if ($argsCount < 3) { $strictArgType = new ConstantBooleanType(false); } else { - $strictArgType = $scope->getType($functionCall->getArgs()[2]->value); + $strictArgType = $scope->getType($args[2]->value); } - $needleArgType = $scope->getType($functionCall->getArgs()[0]->value); + $needleArgType = $scope->getType($args[0]->value); return $haystackArgType->searchArray($needleArgType, $strictArgType->isTrue()); } diff --git a/src/Type/Php/ArrayShiftFunctionReturnTypeExtension.php b/src/Type/Php/ArrayShiftFunctionReturnTypeExtension.php index 704756157d..51e2a534ec 100644 --- a/src/Type/Php/ArrayShiftFunctionReturnTypeExtension.php +++ b/src/Type/Php/ArrayShiftFunctionReturnTypeExtension.php @@ -22,11 +22,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } - $argType = $scope->getType($functionCall->getArgs()[0]->value); + $argType = $scope->getType($args[0]->value); $iterableAtLeastOnce = $argType->isIterableAtLeastOnce(); if ($iterableAtLeastOnce->no()) { return new NullType(); diff --git a/src/Type/Php/ArraySumFunctionDynamicReturnTypeExtension.php b/src/Type/Php/ArraySumFunctionDynamicReturnTypeExtension.php index 061f3d4dff..2107666303 100644 --- a/src/Type/Php/ArraySumFunctionDynamicReturnTypeExtension.php +++ b/src/Type/Php/ArraySumFunctionDynamicReturnTypeExtension.php @@ -28,11 +28,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } - $argType = $scope->getType($functionCall->getArgs()[0]->value); + $argType = $scope->getType($args[0]->value); $resultTypes = []; if (count($argType->getConstantArrays()) > 0) { diff --git a/src/Type/Php/ArrayValuesFunctionDynamicReturnTypeExtension.php b/src/Type/Php/ArrayValuesFunctionDynamicReturnTypeExtension.php index 794b8df7ba..0015c4e126 100644 --- a/src/Type/Php/ArrayValuesFunctionDynamicReturnTypeExtension.php +++ b/src/Type/Php/ArrayValuesFunctionDynamicReturnTypeExtension.php @@ -29,11 +29,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) !== 1) { + $args = $functionCall->getArgs(); + if (count($args) !== 1) { return null; } - $arrayType = $scope->getType($functionCall->getArgs()[0]->value); + $arrayType = $scope->getType($args[0]->value); if ($arrayType->isArray()->no()) { return $this->phpVersion->arrayFunctionsReturnNullWithNonArray() ? new NullType() : new NeverType(); } diff --git a/src/Type/Php/AssertThrowTypeExtension.php b/src/Type/Php/AssertThrowTypeExtension.php index b30bab71cc..1ccd57d402 100644 --- a/src/Type/Php/AssertThrowTypeExtension.php +++ b/src/Type/Php/AssertThrowTypeExtension.php @@ -23,11 +23,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getThrowTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $funcCall, Scope $scope): ?Type { - if (count($funcCall->getArgs()) < 2) { + $args = $funcCall->getArgs(); + if (count($args) < 2) { return $functionReflection->getThrowType(); } - $customThrow = $scope->getType($funcCall->getArgs()[1]->value); + $customThrow = $scope->getType($args[1]->value); if ((new ObjectType(Throwable::class))->isSuperTypeOf($customThrow)->yes()) { return $customThrow; } diff --git a/src/Type/Php/Base64DecodeDynamicFunctionReturnTypeExtension.php b/src/Type/Php/Base64DecodeDynamicFunctionReturnTypeExtension.php index bf91435e62..f12d949d86 100644 --- a/src/Type/Php/Base64DecodeDynamicFunctionReturnTypeExtension.php +++ b/src/Type/Php/Base64DecodeDynamicFunctionReturnTypeExtension.php @@ -29,11 +29,12 @@ public function getTypeFromFunctionCall( Scope $scope, ): Type { - if (!isset($functionCall->getArgs()[1])) { + $args = $functionCall->getArgs(); + if (!isset($args[1])) { return new StringType(); } - $argType = $scope->getType($functionCall->getArgs()[1]->value); + $argType = $scope->getType($args[1]->value); if ($argType instanceof MixedType) { return new BenevolentUnionType([new StringType(), new ConstantBooleanType(false)]); diff --git a/src/Type/Php/BcMathStringOrNullReturnTypeExtension.php b/src/Type/Php/BcMathStringOrNullReturnTypeExtension.php index 0bfede18a1..97ea61c70a 100644 --- a/src/Type/Php/BcMathStringOrNullReturnTypeExtension.php +++ b/src/Type/Php/BcMathStringOrNullReturnTypeExtension.php @@ -47,7 +47,8 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $stringAndNumericStringType = new IntersectionType([new StringType(), new AccessoryNumericStringType()]); - if (isset($functionCall->getArgs()[1]) === false) { + $args = $functionCall->getArgs(); + if (isset($args[1]) === false) { if ($this->phpVersion->throwsTypeErrorForInternalFunctions()) { return new NeverType(); } @@ -61,7 +62,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $defaultReturnType = new UnionType([$stringAndNumericStringType, new NullType()]); } - $secondArgument = $scope->getType($functionCall->getArgs()[1]->value); + $secondArgument = $scope->getType($args[1]->value); $secondArgumentIsNumeric = ($secondArgument instanceof ConstantScalarType && is_numeric($secondArgument->getValue())) || $secondArgument->isInteger()->yes(); if ($secondArgument instanceof ConstantScalarType && ($this->isZero($secondArgument->getValue()) || !$secondArgumentIsNumeric)) { @@ -72,7 +73,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, return new NullType(); } - if (isset($functionCall->getArgs()[2]) === false) { + if (isset($args[2]) === false) { if ($secondArgument instanceof ConstantScalarType || $secondArgumentIsNumeric) { return $stringAndNumericStringType; } @@ -80,7 +81,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, return $defaultReturnType; } - $thirdArgument = $scope->getType($functionCall->getArgs()[2]->value); + $thirdArgument = $scope->getType($args[2]->value); $thirdArgumentIsNumeric = false; $thirdArgumentIsNegative = false; if ($thirdArgument instanceof ConstantScalarType && is_numeric($thirdArgument->getValue())) { @@ -127,7 +128,8 @@ private function getTypeForBcSqrt(FuncCall $functionCall, Scope $scope): Type $defaultReturnType = new UnionType([$stringAndNumericStringType, new NullType()]); } - if (isset($functionCall->getArgs()[0]) === false) { + $args = $functionCall->getArgs(); + if (isset($args[0]) === false) { if ($this->phpVersion->throwsTypeErrorForInternalFunctions()) { return new NeverType(); } @@ -135,7 +137,7 @@ private function getTypeForBcSqrt(FuncCall $functionCall, Scope $scope): Type return $defaultReturnType; } - $firstArgument = $scope->getType($functionCall->getArgs()[0]->value); + $firstArgument = $scope->getType($args[0]->value); $firstArgumentIsPositive = $firstArgument instanceof ConstantScalarType && is_numeric($firstArgument->getValue()) && $firstArgument->getValue() >= 0; $firstArgumentIsNegative = $firstArgument instanceof ConstantScalarType && is_numeric($firstArgument->getValue()) && $firstArgument->getValue() < 0; @@ -148,7 +150,7 @@ private function getTypeForBcSqrt(FuncCall $functionCall, Scope $scope): Type return new NullType(); } - if (isset($functionCall->getArgs()[1]) === false) { + if (isset($args[1]) === false) { if ($firstArgumentIsPositive) { return $stringAndNumericStringType; } @@ -156,7 +158,7 @@ private function getTypeForBcSqrt(FuncCall $functionCall, Scope $scope): Type return $defaultReturnType; } - $secondArgument = $scope->getType($functionCall->getArgs()[1]->value); + $secondArgument = $scope->getType($args[1]->value); $secondArgumentIsValid = $secondArgument instanceof ConstantScalarType && is_numeric($secondArgument->getValue()) && !$this->isZero($secondArgument->getValue()); $secondArgumentIsNonNumeric = $secondArgument instanceof ConstantScalarType && !is_numeric($secondArgument->getValue()); $secondArgumentIsNegative = $secondArgument instanceof ConstantScalarType && is_numeric($secondArgument->getValue()) && $secondArgument->getValue() < 0; @@ -189,13 +191,14 @@ private function getTypeForBcSqrt(FuncCall $functionCall, Scope $scope): Type */ private function getTypeForBcPowMod(FuncCall $functionCall, Scope $scope): Type { - if ($this->phpVersion->throwsTypeErrorForInternalFunctions() && isset($functionCall->getArgs()[0]) === false) { + $args = $functionCall->getArgs(); + if ($this->phpVersion->throwsTypeErrorForInternalFunctions() && isset($args[0]) === false) { return new NeverType(); } $stringAndNumericStringType = new IntersectionType([new StringType(), new AccessoryNumericStringType()]); - if (isset($functionCall->getArgs()[1]) === false) { + if (isset($args[1]) === false) { if ($this->phpVersion->throwsTypeErrorForInternalFunctions()) { return new NeverType(); } @@ -203,7 +206,7 @@ private function getTypeForBcPowMod(FuncCall $functionCall, Scope $scope): Type return new UnionType([$stringAndNumericStringType, new ConstantBooleanType(false)]); } - $exponent = $scope->getType($functionCall->getArgs()[1]->value); + $exponent = $scope->getType($args[1]->value); // Expontent is non numeric if ($this->phpVersion->throwsTypeErrorForInternalFunctions() @@ -226,8 +229,8 @@ private function getTypeForBcPowMod(FuncCall $functionCall, Scope $scope): Type return new ConstantBooleanType(false); } - if (isset($functionCall->getArgs()[2])) { - $modulus = $scope->getType($functionCall->getArgs()[2]->value); + if (isset($args[2])) { + $modulus = $scope->getType($args[2]->value); $modulusIsZero = $modulus instanceof ConstantScalarType && $this->isZero($modulus->getValue()); $modulusIsNonNumeric = $modulus instanceof ConstantScalarType && !is_numeric($modulus->getValue()); diff --git a/src/Type/Php/ClassExistsFunctionTypeSpecifyingExtension.php b/src/Type/Php/ClassExistsFunctionTypeSpecifyingExtension.php index 53cec9a0e6..8265a598b1 100644 --- a/src/Type/Php/ClassExistsFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/ClassExistsFunctionTypeSpecifyingExtension.php @@ -44,7 +44,8 @@ public function isFunctionSupported( public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes { - $argType = $scope->getType($node->getArgs()[0]->value); + $args = $node->getArgs(); + $argType = $scope->getType($args[0]->value); if ($argType instanceof ConstantStringType) { return $this->typeSpecifier->create( new FuncCall(new FullyQualified('class_exists'), [ @@ -62,7 +63,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n } return $this->typeSpecifier->create( - $node->getArgs()[0]->value, + $args[0]->value, $narrowedType, $context, $scope, diff --git a/src/Type/Php/DatePeriodConstructorReturnTypeExtension.php b/src/Type/Php/DatePeriodConstructorReturnTypeExtension.php index b6f2acd839..d7d0633761 100644 --- a/src/Type/Php/DatePeriodConstructorReturnTypeExtension.php +++ b/src/Type/Php/DatePeriodConstructorReturnTypeExtension.php @@ -43,17 +43,18 @@ public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, return null; } - if (!isset($methodCall->getArgs()[0])) { + $args = $methodCall->getArgs(); + if (!isset($args[0])) { return null; } - $firstArgType = $scope->getType($methodCall->getArgs()[0]->value); + $firstArgType = $scope->getType($args[0]->value); if ($firstArgType->isString()->yes()) { $firstArgType = new ObjectType(DateTime::class); } $thirdArgType = null; - if (isset($methodCall->getArgs()[2])) { - $thirdArgType = $scope->getType($methodCall->getArgs()[2]->value); + if (isset($args[2])) { + $thirdArgType = $scope->getType($args[2]->value); } if (!$thirdArgType instanceof Type) { diff --git a/src/Type/Php/DateTimeDynamicReturnTypeExtension.php b/src/Type/Php/DateTimeDynamicReturnTypeExtension.php index eedc6a2fee..bc1ff40375 100644 --- a/src/Type/Php/DateTimeDynamicReturnTypeExtension.php +++ b/src/Type/Php/DateTimeDynamicReturnTypeExtension.php @@ -27,12 +27,13 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 2) { + $args = $functionCall->getArgs(); + if (count($args) < 2) { return null; } - $formats = $scope->getType($functionCall->getArgs()[0]->value)->getConstantStrings(); - $datetimes = $scope->getType($functionCall->getArgs()[1]->value)->getConstantStrings(); + $formats = $scope->getType($args[0]->value)->getConstantStrings(); + $datetimes = $scope->getType($args[1]->value)->getConstantStrings(); if (count($formats) === 0 || count($datetimes) === 0) { return null; diff --git a/src/Type/Php/DefineConstantTypeSpecifyingExtension.php b/src/Type/Php/DefineConstantTypeSpecifyingExtension.php index d71df350c1..290f6fe437 100644 --- a/src/Type/Php/DefineConstantTypeSpecifyingExtension.php +++ b/src/Type/Php/DefineConstantTypeSpecifyingExtension.php @@ -44,7 +44,8 @@ public function specifyTypes( TypeSpecifierContext $context, ): SpecifiedTypes { - $constantName = $scope->getType($node->getArgs()[0]->value); + $args = $node->getArgs(); + $constantName = $scope->getType($args[0]->value); if ( !$constantName instanceof ConstantStringType || $constantName->getValue() === '' @@ -52,7 +53,7 @@ public function specifyTypes( return new SpecifiedTypes([], []); } - $valueType = $scope->getType($node->getArgs()[1]->value); + $valueType = $scope->getType($args[1]->value); $finalType = $scope->getConstantExplicitTypeFromConfig( $constantName->getValue(), $valueType, diff --git a/src/Type/Php/FilterInputDynamicReturnTypeExtension.php b/src/Type/Php/FilterInputDynamicReturnTypeExtension.php index d1679bcdda..79448c9768 100644 --- a/src/Type/Php/FilterInputDynamicReturnTypeExtension.php +++ b/src/Type/Php/FilterInputDynamicReturnTypeExtension.php @@ -25,15 +25,16 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 2) { + $args = $functionCall->getArgs(); + if (count($args) < 2) { return null; } return $this->filterFunctionReturnTypeHelper->getInputType( - $scope->getType($functionCall->getArgs()[0]->value), - $scope->getType($functionCall->getArgs()[1]->value), - isset($functionCall->getArgs()[2]) ? $scope->getType($functionCall->getArgs()[2]->value) : null, - isset($functionCall->getArgs()[3]) ? $scope->getType($functionCall->getArgs()[3]->value) : null, + $scope->getType($args[0]->value), + $scope->getType($args[1]->value), + isset($args[2]) ? $scope->getType($args[2]->value) : null, + isset($args[3]) ? $scope->getType($args[3]->value) : null, ); } diff --git a/src/Type/Php/FilterVarArrayDynamicReturnTypeExtension.php b/src/Type/Php/FilterVarArrayDynamicReturnTypeExtension.php index 77da1d1096..a0442605d7 100644 --- a/src/Type/Php/FilterVarArrayDynamicReturnTypeExtension.php +++ b/src/Type/Php/FilterVarArrayDynamicReturnTypeExtension.php @@ -42,12 +42,13 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 2) { + $args = $functionCall->getArgs(); + if (count($args) < 2) { return null; } $functionName = strtolower($functionReflection->getName()); - $inputArgType = $scope->getType($functionCall->getArgs()[0]->value); + $inputArgType = $scope->getType($args[0]->value); $inputConstantArrayType = null; if ($functionName === 'filter_var_array') { if ($inputArgType->isArray()->no()) { @@ -73,9 +74,9 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $inputArgType = new ArrayType(new StringType(), new MixedType()); } - $filterArgType = $scope->getType($functionCall->getArgs()[1]->value); + $filterArgType = $scope->getType($args[1]->value); $filterConstantArrayType = $filterArgType->getConstantArrays()[0] ?? null; - $addEmptyType = isset($functionCall->getArgs()[2]) ? $scope->getType($functionCall->getArgs()[2]->value) : null; + $addEmptyType = isset($args[2]) ? $scope->getType($args[2]->value) : null; $addEmpty = $addEmptyType === null || $addEmptyType->isTrue()->yes(); $valueTypesBuilder = ConstantArrayTypeBuilder::createEmpty(); diff --git a/src/Type/Php/FilterVarDynamicReturnTypeExtension.php b/src/Type/Php/FilterVarDynamicReturnTypeExtension.php index 1aeacdb0cf..7248566e84 100644 --- a/src/Type/Php/FilterVarDynamicReturnTypeExtension.php +++ b/src/Type/Php/FilterVarDynamicReturnTypeExtension.php @@ -26,13 +26,14 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 1) { + $args = $functionCall->getArgs(); + if (count($args) < 1) { return null; } - $inputType = $scope->getType($functionCall->getArgs()[0]->value); - $filterType = isset($functionCall->getArgs()[1]) ? $scope->getType($functionCall->getArgs()[1]->value) : null; - $flagsType = isset($functionCall->getArgs()[2]) ? $scope->getType($functionCall->getArgs()[2]->value) : null; + $inputType = $scope->getType($args[0]->value); + $filterType = isset($args[1]) ? $scope->getType($args[1]->value) : null; + $flagsType = isset($args[2]) ? $scope->getType($args[2]->value) : null; return $this->filterFunctionReturnTypeHelper->getType($inputType, $filterType, $flagsType); } diff --git a/src/Type/Php/HashFunctionsReturnTypeExtension.php b/src/Type/Php/HashFunctionsReturnTypeExtension.php index 818aa2d16f..935251a359 100644 --- a/src/Type/Php/HashFunctionsReturnTypeExtension.php +++ b/src/Type/Php/HashFunctionsReturnTypeExtension.php @@ -99,7 +99,8 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } @@ -110,8 +111,8 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $functionData = self::SUPPORTED_FUNCTIONS[$lowerFunctionName]; if (is_bool($functionData['binary'])) { $binaryType = new ConstantBooleanType($functionData['binary']); - } elseif (isset($functionCall->getArgs()[$functionData['binary']])) { - $binaryType = $scope->getType($functionCall->getArgs()[$functionData['binary']]->value); + } elseif (isset($args[$functionData['binary']])) { + $binaryType = $scope->getType($args[$functionData['binary']]->value); } else { $binaryType = new ConstantBooleanType(false); } @@ -125,7 +126,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, } $stringReturnType = new IntersectionType($stringTypes); - $algorithmType = $scope->getType($functionCall->getArgs()[0]->value); + $algorithmType = $scope->getType($args[0]->value); $constantAlgorithmTypes = $algorithmType->getConstantStrings(); if (count($constantAlgorithmTypes) === 0) { if ($functionData['possiblyFalse'] || !$this->phpVersion->throwsValueErrorForInternalFunctions()) { diff --git a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php index 0333111b2f..0af00a4ffb 100644 --- a/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/InArrayFunctionTypeSpecifyingExtension.php @@ -41,19 +41,20 @@ public function isFunctionSupported(FunctionReflection $functionReflection, Func public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes { - $argsCount = count($node->getArgs()); + $args = $node->getArgs(); + $argsCount = count($args); if ($argsCount < 2) { return new SpecifiedTypes(); } $isStrictComparison = false; if ($argsCount >= 3) { - $strictNodeType = $scope->getType($node->getArgs()[2]->value); + $strictNodeType = $scope->getType($args[2]->value); $isStrictComparison = $strictNodeType->isTrue()->yes(); } - $needleExpr = $node->getArgs()[0]->value; - $arrayExpr = $node->getArgs()[1]->value; + $needleExpr = $args[0]->value; + $arrayExpr = $args[1]->value; $needleType = $scope->getType($needleExpr); $arrayType = $scope->getType($arrayExpr); @@ -101,7 +102,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n && $arrayType->getIterableValueType()->isSuperTypeOf($needleType)->yes() ) { return $this->typeSpecifier->create( - $node->getArgs()[1]->value, + $args[1]->value, TypeCombinator::intersect($arrayType, new NonEmptyArrayType()), $context, $scope, @@ -151,7 +152,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n } $specifiedTypes = $specifiedTypes->unionWith($this->typeSpecifier->create( - $node->getArgs()[1]->value, + $args[1]->value, new ArrayType(new MixedType(), $arrayValueType), TypeSpecifierContext::createTrue(), $scope, @@ -160,7 +161,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n if ($context->true() && $arrayType->isArray()->yes()) { $specifiedTypes = $specifiedTypes->unionWith($this->typeSpecifier->create( - $node->getArgs()[1]->value, + $args[1]->value, TypeCombinator::intersect($arrayType, new NonEmptyArrayType()), $context, $scope, diff --git a/src/Type/Php/IntdivThrowTypeExtension.php b/src/Type/Php/IntdivThrowTypeExtension.php index baab09248b..f76d2cfb07 100644 --- a/src/Type/Php/IntdivThrowTypeExtension.php +++ b/src/Type/Php/IntdivThrowTypeExtension.php @@ -26,14 +26,15 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getThrowTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $funcCall, Scope $scope): ?Type { - if (count($funcCall->getArgs()) < 2) { + $args = $funcCall->getArgs(); + if (count($args) < 2) { return $functionReflection->getThrowType(); } - $valueType = $scope->getType($funcCall->getArgs()[0]->value)->toInteger(); + $valueType = $scope->getType($args[0]->value)->toInteger(); $containsMin = $valueType->isSuperTypeOf(new ConstantIntegerType(PHP_INT_MIN)); - $divisorType = $scope->getType($funcCall->getArgs()[1]->value)->toInteger(); + $divisorType = $scope->getType($args[1]->value)->toInteger(); if (!$containsMin->no()) { $divisionByMinusOne = $divisorType->isSuperTypeOf(new ConstantIntegerType(-1)); if (!$divisionByMinusOne->no()) { diff --git a/src/Type/Php/IsAFunctionTypeSpecifyingExtension.php b/src/Type/Php/IsAFunctionTypeSpecifyingExtension.php index 5d19e4950f..a233ae1d83 100644 --- a/src/Type/Php/IsAFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/IsAFunctionTypeSpecifyingExtension.php @@ -36,17 +36,18 @@ public function isFunctionSupported(FunctionReflection $functionReflection, Func public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes { - if (count($node->getArgs()) < 2) { + $args = $node->getArgs(); + if (count($args) < 2) { return new SpecifiedTypes(); } - $classType = $scope->getType($node->getArgs()[1]->value); + $classType = $scope->getType($args[1]->value); if (!$classType instanceof ConstantStringType && !$context->true()) { return new SpecifiedTypes([], []); } - $objectOrClassType = $scope->getType($node->getArgs()[0]->value); - $allowStringType = isset($node->getArgs()[2]) ? $scope->getType($node->getArgs()[2]->value) : new ConstantBooleanType(false); + $objectOrClassType = $scope->getType($args[0]->value); + $allowStringType = isset($args[2]) ? $scope->getType($args[2]->value) : new ConstantBooleanType(false); $allowString = !$allowStringType->equals(new ConstantBooleanType(false)); $resultType = $this->isAFunctionTypeSpecifyingHelper->determineType($objectOrClassType, $classType, $allowString, true); @@ -57,7 +58,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n } return $this->typeSpecifier->create( - $node->getArgs()[0]->value, + $args[0]->value, $resultType, $context, $scope, diff --git a/src/Type/Php/IsSubclassOfFunctionTypeSpecifyingExtension.php b/src/Type/Php/IsSubclassOfFunctionTypeSpecifyingExtension.php index e910bd5ea1..49dd10e80d 100644 --- a/src/Type/Php/IsSubclassOfFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/IsSubclassOfFunctionTypeSpecifyingExtension.php @@ -36,13 +36,14 @@ public function isFunctionSupported(FunctionReflection $functionReflection, Func public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes { - if (!$context->true() || count($node->getArgs()) < 2) { + $args = $node->getArgs(); + if (!$context->true() || count($args) < 2) { return new SpecifiedTypes(); } - $objectOrClassType = $scope->getType($node->getArgs()[0]->value); - $classType = $scope->getType($node->getArgs()[1]->value); - $allowStringType = isset($node->getArgs()[2]) ? $scope->getType($node->getArgs()[2]->value) : new ConstantBooleanType(true); + $objectOrClassType = $scope->getType($args[0]->value); + $classType = $scope->getType($args[1]->value); + $allowStringType = isset($args[2]) ? $scope->getType($args[2]->value) : new ConstantBooleanType(true); $allowString = !$allowStringType->equals(new ConstantBooleanType(false)); // prevent false-positives in IsAFunctionTypeSpecifyingHelper @@ -58,7 +59,7 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n } return $this->typeSpecifier->create( - $node->getArgs()[0]->value, + $args[0]->value, $resultType, $context, $scope, diff --git a/src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php b/src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php index 3d320abd89..c5b419803f 100644 --- a/src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php +++ b/src/Type/Php/JsonThrowOnErrorDynamicReturnTypeExtension.php @@ -56,9 +56,10 @@ public function getTypeFromFunctionCall( ): Type { $argumentPosition = $this->argumentPositions[$functionReflection->getName()]; + $args = $functionCall->getArgs(); $defaultReturnType = ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->getArgs(), + $args, $functionReflection->getVariants(), )->getReturnType(); @@ -66,11 +67,11 @@ public function getTypeFromFunctionCall( $defaultReturnType = $this->narrowTypeForJsonDecode($functionCall, $scope, $defaultReturnType); } - if (!isset($functionCall->getArgs()[$argumentPosition])) { + if (!isset($args[$argumentPosition])) { return $defaultReturnType; } - $optionsExpr = $functionCall->getArgs()[$argumentPosition]->value; + $optionsExpr = $args[$argumentPosition]->value; if ($functionReflection->getName() === 'json_encode' && $this->bitwiseFlagAnalyser->bitwiseOrContainsConstant($optionsExpr, $scope, 'JSON_THROW_ON_ERROR')->yes()) { return TypeCombinator::remove($defaultReturnType, new ConstantBooleanType(false)); } diff --git a/src/Type/Php/JsonThrowTypeExtension.php b/src/Type/Php/JsonThrowTypeExtension.php index bb5d21007c..e199744999 100644 --- a/src/Type/Php/JsonThrowTypeExtension.php +++ b/src/Type/Php/JsonThrowTypeExtension.php @@ -56,11 +56,12 @@ public function getThrowTypeFromFunctionCall( throw new ShouldNotHappenException(); } $argumentPosition = self::ARGUMENTS_POSITIONS[$functionReflection->getName()]; - if (!isset($functionCall->getArgs()[$argumentPosition])) { + $args = $functionCall->getArgs(); + if (!isset($args[$argumentPosition])) { return null; } - $optionsExpr = $functionCall->getArgs()[$argumentPosition]->value; + $optionsExpr = $args[$argumentPosition]->value; if (!$this->bitwiseFlagAnalyser->bitwiseOrContainsConstant($optionsExpr, $scope, 'JSON_THROW_ON_ERROR')->no()) { return new ObjectType('JsonException'); } diff --git a/src/Type/Php/LtrimFunctionReturnTypeExtension.php b/src/Type/Php/LtrimFunctionReturnTypeExtension.php index 24db9d1304..9cf4b23cf6 100644 --- a/src/Type/Php/LtrimFunctionReturnTypeExtension.php +++ b/src/Type/Php/LtrimFunctionReturnTypeExtension.php @@ -31,11 +31,12 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 1) { + $args = $functionCall->getArgs(); + if (count($args) < 1) { return null; } - $string = $scope->getType($functionCall->getArgs()[0]->value); + $string = $scope->getType($args[0]->value); $accessory = []; $defaultType = new StringType(); @@ -50,11 +51,11 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $defaultType = new IntersectionType($accessory); } - if (count($functionCall->getArgs()) !== 2) { + if (count($args) !== 2) { return $defaultType; } - $trimChars = $scope->getType($functionCall->getArgs()[1]->value); + $trimChars = $scope->getType($args[1]->value); $trimConstantStrings = $trimChars->getConstantStrings(); if (count($trimConstantStrings) > 0) { diff --git a/src/Type/Php/MbConvertEncodingFunctionReturnTypeExtension.php b/src/Type/Php/MbConvertEncodingFunctionReturnTypeExtension.php index f12efd095c..310045be6e 100644 --- a/src/Type/Php/MbConvertEncodingFunctionReturnTypeExtension.php +++ b/src/Type/Php/MbConvertEncodingFunctionReturnTypeExtension.php @@ -42,15 +42,16 @@ public function getTypeFromFunctionCall( Scope $scope, ): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } - $argType = $scope->getType($functionCall->getArgs()[0]->value); + $argType = $scope->getType($args[0]->value); $initialReturnType = ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->getArgs(), + $args, $functionReflection->getVariants(), )->getReturnType(); @@ -60,10 +61,10 @@ public function getTypeFromFunctionCall( } if ($this->phpVersion->throwsValueErrorForInternalFunctions()) { - if (!isset($functionCall->getArgs()[2])) { + if (!isset($args[2])) { return TypeCombinator::remove($result, new ConstantBooleanType(false)); } - $fromEncodingArgType = $scope->getType($functionCall->getArgs()[2]->value); + $fromEncodingArgType = $scope->getType($args[2]->value); $returnFalseIfCannotDetectEncoding = false; if (!$fromEncodingArgType->isArray()->no()) { diff --git a/src/Type/Php/MbFunctionsReturnTypeExtension.php b/src/Type/Php/MbFunctionsReturnTypeExtension.php index 596e2ed8c1..659bd9f007 100644 --- a/src/Type/Php/MbFunctionsReturnTypeExtension.php +++ b/src/Type/Php/MbFunctionsReturnTypeExtension.php @@ -49,18 +49,19 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { + $args = $functionCall->getArgs(); $returnType = ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->getArgs(), + $args, $functionReflection->getVariants(), )->getReturnType(); $positionEncodingParam = $this->encodingPositionMap[$functionReflection->getName()]; - if (count($functionCall->getArgs()) < $positionEncodingParam) { + if (count($args) < $positionEncodingParam) { return TypeCombinator::remove($returnType, new BooleanType()); } - $strings = $scope->getType($functionCall->getArgs()[$positionEncodingParam - 1]->value)->getConstantStrings(); + $strings = $scope->getType($args[$positionEncodingParam - 1]->value)->getConstantStrings(); $results = array_unique(array_map(fn (ConstantStringType $encoding): bool => $this->isSupportedEncoding($encoding->getValue()), $strings)); if ($returnType->equals(new UnionType([new StringType(), new BooleanType()]))) { diff --git a/src/Type/Php/MbStrlenFunctionReturnTypeExtension.php b/src/Type/Php/MbStrlenFunctionReturnTypeExtension.php index 7614786dbf..ee57cc3f16 100644 --- a/src/Type/Php/MbStrlenFunctionReturnTypeExtension.php +++ b/src/Type/Php/MbStrlenFunctionReturnTypeExtension.php @@ -64,13 +64,13 @@ public function getTypeFromFunctionCall( $encodings = []; - if (count($functionCall->getArgs()) === 1) { + if (count($args) === 1) { // there is a chance to get an unsupported encoding 'pass' or 'none' here on PHP 7.3-7.4 $encodings = [mb_internal_encoding()]; - } elseif (count($functionCall->getArgs()) === 2) { // custom encoding is specified + } elseif (count($args) === 2) { // custom encoding is specified $encodings = array_map( static fn (ConstantStringType $t) => $t->getValue(), - $scope->getType($functionCall->getArgs()[1]->value)->getConstantStrings(), + $scope->getType($args[1]->value)->getConstantStrings(), ); } @@ -138,7 +138,7 @@ public function getTypeFromFunctionCall( $range = TypeCombinator::remove( ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->getArgs(), + $args, $functionReflection->getVariants(), )->getReturnType(), new ConstantBooleanType(false), diff --git a/src/Type/Php/MethodExistsTypeSpecifyingExtension.php b/src/Type/Php/MethodExistsTypeSpecifyingExtension.php index 3db54618e5..3e42c9c42e 100644 --- a/src/Type/Php/MethodExistsTypeSpecifyingExtension.php +++ b/src/Type/Php/MethodExistsTypeSpecifyingExtension.php @@ -50,7 +50,8 @@ public function specifyTypes( TypeSpecifierContext $context, ): SpecifiedTypes { - $methodNameType = $scope->getType($node->getArgs()[1]->value); + $args = $node->getArgs(); + $methodNameType = $scope->getType($args[1]->value); if (!$methodNameType instanceof ConstantStringType) { return $this->typeSpecifier->create( new FuncCall(new FullyQualified('method_exists'), $node->getRawArgs()), @@ -60,11 +61,11 @@ public function specifyTypes( ); } - $objectType = $scope->getType($node->getArgs()[0]->value); + $objectType = $scope->getType($args[0]->value); if ($objectType->isString()->yes()) { if ($objectType->isClassString()->yes()) { return $this->typeSpecifier->create( - $node->getArgs()[0]->value, + $args[0]->value, new IntersectionType([ $objectType, new HasMethodType($methodNameType->getValue()), @@ -78,7 +79,7 @@ public function specifyTypes( } return $this->typeSpecifier->create( - $node->getArgs()[0]->value, + $args[0]->value, new UnionType([ new IntersectionType([ new ObjectWithoutClassType(), diff --git a/src/Type/Php/MinMaxFunctionReturnTypeExtension.php b/src/Type/Php/MinMaxFunctionReturnTypeExtension.php index 0c4ea75b0f..b425174cd7 100644 --- a/src/Type/Php/MinMaxFunctionReturnTypeExtension.php +++ b/src/Type/Php/MinMaxFunctionReturnTypeExtension.php @@ -38,12 +38,13 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (!isset($functionCall->getArgs()[0])) { + $args = $functionCall->getArgs(); + if (!isset($args[0])) { return null; } - if (count($functionCall->getArgs()) === 1) { - $argType = $scope->getType($functionCall->getArgs()[0]->value); + if (count($args) === 1) { + $argType = $scope->getType($args[0]->value); if ($argType->isArray()->yes()) { return $this->processArrayType( $functionReflection->getName(), @@ -57,8 +58,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, // rewrite min($x, $y) as $x < $y ? $x : $y // we don't handle arrays, which have different semantics $functionName = $functionReflection->getName(); - $args = $functionCall->getArgs(); - if (count($functionCall->getArgs()) === 2) { + if (count($args) === 2) { $argType0 = $scope->getType($args[0]->value); $argType1 = $scope->getType($args[1]->value); @@ -85,7 +85,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, } $argumentTypes = []; - foreach ($functionCall->getArgs() as $arg) { + foreach ($args as $arg) { $argType = $scope->getType($arg->value); if ($arg->unpack) { $iterableValueType = $argType->getIterableValueType(); diff --git a/src/Type/Php/ParseUrlFunctionDynamicReturnTypeExtension.php b/src/Type/Php/ParseUrlFunctionDynamicReturnTypeExtension.php index a0a04134e9..962023a5ca 100644 --- a/src/Type/Php/ParseUrlFunctionDynamicReturnTypeExtension.php +++ b/src/Type/Php/ParseUrlFunctionDynamicReturnTypeExtension.php @@ -59,15 +59,16 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 1) { + $args = $functionCall->getArgs(); + if (count($args) < 1) { return null; } $this->cacheReturnTypes(); - $urlType = $scope->getType($functionCall->getArgs()[0]->value); - if (count($functionCall->getArgs()) > 1) { - $componentType = $scope->getType($functionCall->getArgs()[1]->value); + $urlType = $scope->getType($args[0]->value); + if (count($args) > 1) { + $componentType = $scope->getType($args[1]->value); if (!$componentType->isConstantValue()->yes()) { return $this->createAllComponentsReturnType($urlType->isLowercaseString()->yes()); diff --git a/src/Type/Php/PathinfoFunctionDynamicReturnTypeExtension.php b/src/Type/Php/PathinfoFunctionDynamicReturnTypeExtension.php index 05a8a8ea6b..0263a495e6 100644 --- a/src/Type/Php/PathinfoFunctionDynamicReturnTypeExtension.php +++ b/src/Type/Php/PathinfoFunctionDynamicReturnTypeExtension.php @@ -38,12 +38,13 @@ public function getTypeFromFunctionCall( Scope $scope, ): ?Type { - $argsCount = count($functionCall->getArgs()); + $args = $functionCall->getArgs(); + $argsCount = count($args); if ($argsCount === 0) { return null; } - $pathType = $scope->getType($functionCall->getArgs()[0]->value); + $pathType = $scope->getType($args[0]->value); $builder = ConstantArrayTypeBuilder::createEmpty(); $builder->setOffsetValueType(new ConstantStringType('dirname'), new StringType(), !$pathType->isNonEmptyString()->yes()); @@ -56,7 +57,7 @@ public function getTypeFromFunctionCall( return $arrayType; } - $flagsType = $scope->getType($functionCall->getArgs()[1]->value); + $flagsType = $scope->getType($args[1]->value); $scalarValues = $flagsType->getConstantScalarValues(); if ($scalarValues !== []) { diff --git a/src/Type/Php/PregFilterFunctionReturnTypeExtension.php b/src/Type/Php/PregFilterFunctionReturnTypeExtension.php index 6d6660d362..295cba24ec 100644 --- a/src/Type/Php/PregFilterFunctionReturnTypeExtension.php +++ b/src/Type/Php/PregFilterFunctionReturnTypeExtension.php @@ -27,18 +27,19 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { + $args = $functionCall->getArgs(); $defaultReturn = ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->getArgs(), + $args, $functionReflection->getVariants(), )->getReturnType(); - $argsCount = count($functionCall->getArgs()); + $argsCount = count($args); if ($argsCount < 3) { return $defaultReturn; } - $subjectType = $scope->getType($functionCall->getArgs()[2]->value); + $subjectType = $scope->getType($args[2]->value); if ($subjectType->isArray()->yes()) { return new ArrayType(new IntegerType(), new StringType()); diff --git a/src/Type/Php/PropertyExistsTypeSpecifyingExtension.php b/src/Type/Php/PropertyExistsTypeSpecifyingExtension.php index e62a04d409..b299f6f14f 100644 --- a/src/Type/Php/PropertyExistsTypeSpecifyingExtension.php +++ b/src/Type/Php/PropertyExistsTypeSpecifyingExtension.php @@ -55,7 +55,8 @@ public function specifyTypes( TypeSpecifierContext $context, ): SpecifiedTypes { - $propertyNameType = $scope->getType($node->getArgs()[1]->value); + $args = $node->getArgs(); + $propertyNameType = $scope->getType($args[1]->value); if (!$propertyNameType instanceof ConstantStringType) { return $this->typeSpecifier->create( new FuncCall(new FullyQualified('property_exists'), $node->getRawArgs()), @@ -69,12 +70,12 @@ public function specifyTypes( return new SpecifiedTypes([], []); } - $objectType = $scope->getType($node->getArgs()[0]->value); + $objectType = $scope->getType($args[0]->value); if ($objectType instanceof ConstantStringType) { return new SpecifiedTypes([], []); } elseif ($objectType->isObject()->yes()) { $propertyNode = new PropertyFetch( - $node->getArgs()[0]->value, + $args[0]->value, new Identifier($propertyNameType->getValue()), ); } else { @@ -89,7 +90,7 @@ public function specifyTypes( } return $this->typeSpecifier->create( - $node->getArgs()[0]->value, + $args[0]->value, new IntersectionType([ new ObjectWithoutClassType(), new HasPropertyType($propertyNameType->getValue()), diff --git a/src/Type/Php/RandomIntFunctionReturnTypeExtension.php b/src/Type/Php/RandomIntFunctionReturnTypeExtension.php index 35f978e631..9e8fbac412 100644 --- a/src/Type/Php/RandomIntFunctionReturnTypeExtension.php +++ b/src/Type/Php/RandomIntFunctionReturnTypeExtension.php @@ -29,16 +29,17 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (in_array($functionReflection->getName(), ['rand', 'mt_rand'], true) && count($functionCall->getArgs()) === 0) { + $args = $functionCall->getArgs(); + if (in_array($functionReflection->getName(), ['rand', 'mt_rand'], true) && count($args) === 0) { return IntegerRangeType::fromInterval(0, null); } - if (count($functionCall->getArgs()) < 2) { + if (count($args) < 2) { return null; } - $minType = $scope->getType($functionCall->getArgs()[0]->value)->toInteger(); - $maxType = $scope->getType($functionCall->getArgs()[1]->value)->toInteger(); + $minType = $scope->getType($args[0]->value)->toInteger(); + $maxType = $scope->getType($args[1]->value)->toInteger(); return $this->createRange($minType, $maxType); } diff --git a/src/Type/Php/RangeFunctionReturnTypeExtension.php b/src/Type/Php/RangeFunctionReturnTypeExtension.php index 45f6fffc9e..15ff3d618f 100644 --- a/src/Type/Php/RangeFunctionReturnTypeExtension.php +++ b/src/Type/Php/RangeFunctionReturnTypeExtension.php @@ -42,13 +42,14 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 2) { + $args = $functionCall->getArgs(); + if (count($args) < 2) { return null; } - $startType = $scope->getType($functionCall->getArgs()[0]->value); - $endType = $scope->getType($functionCall->getArgs()[1]->value); - $stepType = count($functionCall->getArgs()) >= 3 ? $scope->getType($functionCall->getArgs()[2]->value) : new ConstantIntegerType(1); + $startType = $scope->getType($args[0]->value); + $endType = $scope->getType($args[1]->value); + $stepType = count($args) >= 3 ? $scope->getType($args[2]->value) : new ConstantIntegerType(1); $constantReturnTypes = []; diff --git a/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php b/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php index 57e3b76710..5df70cd0ed 100644 --- a/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php +++ b/src/Type/Php/ReplaceFunctionsDynamicReturnTypeExtension.php @@ -76,9 +76,10 @@ private function getPreliminarilyResolvedTypeFromFunctionCall( ): Type { $subjectArgumentType = $this->getSubjectType($functionReflection, $functionCall, $scope); + $args = $functionCall->getArgs(); $defaultReturnType = ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->getArgs(), + $args, $functionReflection->getVariants(), )->getReturnType(); @@ -94,8 +95,8 @@ private function getPreliminarilyResolvedTypeFromFunctionCall( if (array_key_exists($functionReflection->getName(), self::FUNCTIONS_REPLACE_POSITION)) { $replaceArgumentPosition = self::FUNCTIONS_REPLACE_POSITION[$functionReflection->getName()]; - if (count($functionCall->getArgs()) > $replaceArgumentPosition) { - $replaceArgumentType = $scope->getType($functionCall->getArgs()[$replaceArgumentPosition]->value); + if (count($args) > $replaceArgumentPosition) { + $replaceArgumentType = $scope->getType($args[$replaceArgumentPosition]->value); if ($replaceArgumentType->isArray()->yes()) { $replaceArgumentType = $replaceArgumentType->getIterableValueType(); } @@ -202,10 +203,11 @@ private function getSubjectType( } $argumentPosition = self::FUNCTIONS_SUBJECT_POSITION[$functionReflection->getName()]; - if (count($functionCall->getArgs()) <= $argumentPosition) { + $args = $functionCall->getArgs(); + if (count($args) <= $argumentPosition) { return null; } - return $scope->getType($functionCall->getArgs()[$argumentPosition]->value); + return $scope->getType($args[$argumentPosition]->value); } private function canReturnNull( @@ -214,9 +216,10 @@ private function canReturnNull( Scope $scope, ): bool { + $args = $functionCall->getArgs(); if ( in_array($functionReflection->getName(), ['preg_replace', 'preg_replace_callback', 'preg_replace_callback_array'], true) - && count($functionCall->getArgs()) > 0 + && count($args) > 0 ) { $subjectArgumentType = $this->getSubjectType($functionReflection, $functionCall, $scope); @@ -230,7 +233,7 @@ private function canReturnNull( $possibleTypes = ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->getArgs(), + $args, $functionReflection->getVariants(), )->getReturnType(); diff --git a/src/Type/Php/SetTypeFunctionTypeSpecifyingExtension.php b/src/Type/Php/SetTypeFunctionTypeSpecifyingExtension.php index 32373fcf7a..88c9dd86fc 100644 --- a/src/Type/Php/SetTypeFunctionTypeSpecifyingExtension.php +++ b/src/Type/Php/SetTypeFunctionTypeSpecifyingExtension.php @@ -34,9 +34,10 @@ public function isFunctionSupported(FunctionReflection $functionReflection, Func public function specifyTypes(FunctionReflection $functionReflection, FuncCall $node, Scope $scope, TypeSpecifierContext $context): SpecifiedTypes { - $value = $node->getArgs()[0]->value; + $args = $node->getArgs(); + $value = $args[0]->value; $valueType = $scope->getType($value); - $castType = $scope->getType($node->getArgs()[1]->value); + $castType = $scope->getType($args[1]->value); $constantStrings = $castType->getConstantStrings(); if (count($constantStrings) < 1) { diff --git a/src/Type/Php/StrSplitFunctionReturnTypeExtension.php b/src/Type/Php/StrSplitFunctionReturnTypeExtension.php index f5f120389d..9738902437 100644 --- a/src/Type/Php/StrSplitFunctionReturnTypeExtension.php +++ b/src/Type/Php/StrSplitFunctionReturnTypeExtension.php @@ -51,12 +51,13 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): ?Type { - if (count($functionCall->getArgs()) < 1) { + $args = $functionCall->getArgs(); + if (count($args) < 1) { return null; } - if (count($functionCall->getArgs()) >= 2) { - $splitLengthType = $scope->getType($functionCall->getArgs()[1]->value); + if (count($args) >= 2) { + $splitLengthType = $scope->getType($args[1]->value); } else { $splitLengthType = new ConstantIntegerType(1); } @@ -70,8 +71,8 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $encoding = null; if ($functionReflection->getName() === 'mb_str_split') { - if (count($functionCall->getArgs()) >= 3) { - $strings = $scope->getType($functionCall->getArgs()[2]->value)->getConstantStrings(); + if (count($args) >= 3) { + $strings = $scope->getType($args[2]->value)->getConstantStrings(); $values = array_unique(array_map(static fn (ConstantStringType $encoding): string => $encoding->getValue(), $strings)); if (count($values) === 1) { @@ -85,7 +86,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, } } - $stringType = $scope->getType($functionCall->getArgs()[0]->value); + $stringType = $scope->getType($args[0]->value); if ( isset($splitLength) && ($functionReflection->getName() === 'str_split' || $encoding !== null) diff --git a/src/Type/Php/StrtotimeFunctionReturnTypeExtension.php b/src/Type/Php/StrtotimeFunctionReturnTypeExtension.php index 284759e59e..21e431dab2 100644 --- a/src/Type/Php/StrtotimeFunctionReturnTypeExtension.php +++ b/src/Type/Php/StrtotimeFunctionReturnTypeExtension.php @@ -33,15 +33,16 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { + $args = $functionCall->getArgs(); $defaultReturnType = ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->getArgs(), + $args, $functionReflection->getVariants(), )->getReturnType(); - if (count($functionCall->getArgs()) === 0) { + if (count($args) === 0) { return $defaultReturnType; } - $argType = $scope->getType($functionCall->getArgs()[0]->value); + $argType = $scope->getType($args[0]->value); if ($argType instanceof MixedType) { return TypeUtils::toBenevolentUnion($defaultReturnType); } @@ -57,7 +58,7 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, } // 2nd param $baseTimestamp is too non-deterministic so simply return int - if (count($functionCall->getArgs()) > 1) { + if (count($args) > 1) { return new IntegerType(); } diff --git a/src/Type/Php/TrimFunctionDynamicReturnTypeExtension.php b/src/Type/Php/TrimFunctionDynamicReturnTypeExtension.php index c7df164334..f54271fc50 100644 --- a/src/Type/Php/TrimFunctionDynamicReturnTypeExtension.php +++ b/src/Type/Php/TrimFunctionDynamicReturnTypeExtension.php @@ -55,11 +55,11 @@ public function getTypeFromFunctionCall( $defaultType = new IntersectionType($accessory); } - if (count($functionCall->getArgs()) !== 2) { + if (count($args) !== 2) { return $defaultType; } - $trimChars = $scope->getType($functionCall->getArgs()[1]->value); + $trimChars = $scope->getType($args[1]->value); $trimConstantStrings = $trimChars->getConstantStrings(); if (count($trimConstantStrings) > 0) {