diff --git a/composer.json b/composer.json index 0fe47ad..3d7e780 100644 --- a/composer.json +++ b/composer.json @@ -19,7 +19,6 @@ "require-dev": { "composer/composer": "^1.10.23", "dealerdirect/phpcodesniffer-composer-installer": "^0.7", - "nikic/php-parser": "< 4.13.0", "php-parallel-lint/php-parallel-lint": "^1.1", "phpstan/phpstan-strict-rules": "^1.0", "phpunit/phpunit": "^7 || ^9", diff --git a/src/CurrentTimeDynamicFunctionReturnTypeExtension.php b/src/CurrentTimeDynamicFunctionReturnTypeExtension.php index 22dc59b..913ca23 100644 --- a/src/CurrentTimeDynamicFunctionReturnTypeExtension.php +++ b/src/CurrentTimeDynamicFunctionReturnTypeExtension.php @@ -29,13 +29,14 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo */ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { - $argumentType = $scope->getType($functionCall->args[0]->value); + $args = $functionCall->getArgs(); + $argumentType = $scope->getType($args[0]->value); // When called with a $type that isn't a constant string, return default return type if (! $argumentType instanceof ConstantStringType) { return ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->args, + $args, $functionReflection->getVariants() )->getReturnType(); } diff --git a/src/GetCommentDynamicFunctionReturnTypeExtension.php b/src/GetCommentDynamicFunctionReturnTypeExtension.php index f0bc4bb..bb3331b 100644 --- a/src/GetCommentDynamicFunctionReturnTypeExtension.php +++ b/src/GetCommentDynamicFunctionReturnTypeExtension.php @@ -34,22 +34,23 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { $output = 'OBJECT'; + $args = $functionCall->getArgs(); - if (count($functionCall->args) >= 2) { - $argumentType = $scope->getType($functionCall->args[1]->value); + if (count($args) >= 2) { + $argumentType = $scope->getType($args[1]->value); // When called with an $output that isn't a constant string, return default return type if (! $argumentType instanceof ConstantStringType) { return ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->args, + $args, $functionReflection->getVariants() )->getReturnType(); } } - if (count($functionCall->args) >= 2 && $functionCall->args[1]->value instanceof ConstFetch) { - $output = $functionCall->args[1]->value->name->getLast(); + if (count($args) >= 2 && $args[1]->value instanceof ConstFetch) { + $output = $args[1]->value->name->getLast(); } if ($output === 'ARRAY_A') { return TypeCombinator::union(new ArrayType(new StringType(), new MixedType()), new NullType()); diff --git a/src/GetListTableDynamicFunctionReturnTypeExtension.php b/src/GetListTableDynamicFunctionReturnTypeExtension.php index 4beecc9..698b83b 100644 --- a/src/GetListTableDynamicFunctionReturnTypeExtension.php +++ b/src/GetListTableDynamicFunctionReturnTypeExtension.php @@ -28,18 +28,20 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo // phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { + $args = $functionCall->getArgs(); + // Called without $class argument - if (count($functionCall->args) < 1) { + if (count($args) < 1) { return new ConstantBooleanType(false); } - $argumentType = $scope->getType($functionCall->args[0]->value); + $argumentType = $scope->getType($args[0]->value); // When called with a $class that isn't a constant string, return default return type if (! $argumentType instanceof ConstantStringType) { return ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->args, + $args, $functionReflection->getVariants() )->getReturnType(); } diff --git a/src/GetObjectTaxonomiesDynamicFunctionReturnTypeExtension.php b/src/GetObjectTaxonomiesDynamicFunctionReturnTypeExtension.php index 14c0073..0f8ed9a 100644 --- a/src/GetObjectTaxonomiesDynamicFunctionReturnTypeExtension.php +++ b/src/GetObjectTaxonomiesDynamicFunctionReturnTypeExtension.php @@ -33,18 +33,20 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo */ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { + $args = $functionCall->getArgs(); + // Called without second $output argument - if (count($functionCall->args) <= 1) { + if (count($args) <= 1) { return new ArrayType(new IntegerType(), new StringType()); } - $argumentType = $scope->getType($functionCall->args[1]->value); + $argumentType = $scope->getType($args[1]->value); // When called with an $output that isn't a constant string, return default return type if (! $argumentType instanceof ConstantStringType) { return ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->args, + $args, $functionReflection->getVariants() )->getReturnType(); } diff --git a/src/GetPostDynamicFunctionReturnTypeExtension.php b/src/GetPostDynamicFunctionReturnTypeExtension.php index 157f212..ae3d236 100644 --- a/src/GetPostDynamicFunctionReturnTypeExtension.php +++ b/src/GetPostDynamicFunctionReturnTypeExtension.php @@ -34,22 +34,23 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { $output = 'OBJECT'; + $args = $functionCall->getArgs(); if (count($functionCall->args) >= 2) { - $argumentType = $scope->getType($functionCall->args[1]->value); + $argumentType = $scope->getType($args[1]->value); // When called with an $output that isn't a constant string, return default return type if (! $argumentType instanceof ConstantStringType) { return ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->args, + $args, $functionReflection->getVariants() )->getReturnType(); } } - if (count($functionCall->args) >= 2 && $functionCall->args[1]->value instanceof ConstFetch) { - $output = $functionCall->args[1]->value->name->getLast(); + if (count($args) >= 2 && $args[1]->value instanceof ConstFetch) { + $output = $args[1]->value->name->getLast(); } if ($output === 'ARRAY_A') { return TypeCombinator::union(new ArrayType(new StringType(), new MixedType()), new NullType()); diff --git a/src/GetPostsDynamicFunctionReturnTypeExtension.php b/src/GetPostsDynamicFunctionReturnTypeExtension.php index d458692..26ffb59 100644 --- a/src/GetPostsDynamicFunctionReturnTypeExtension.php +++ b/src/GetPostsDynamicFunctionReturnTypeExtension.php @@ -31,12 +31,14 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo // phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { + $args = $functionCall->getArgs(); + // Called without arguments - if (count($functionCall->args) === 0) { + if (count($args) === 0) { return new ArrayType(new IntegerType(), new ObjectType('WP_Post')); } - $argumentType = $scope->getType($functionCall->args[0]->value); + $argumentType = $scope->getType($args[0]->value); // Called with an array argument if ($argumentType instanceof ConstantArrayType) { diff --git a/src/GetTaxonomiesDynamicFunctionReturnTypeExtension.php b/src/GetTaxonomiesDynamicFunctionReturnTypeExtension.php index a663b7c..deed580 100644 --- a/src/GetTaxonomiesDynamicFunctionReturnTypeExtension.php +++ b/src/GetTaxonomiesDynamicFunctionReturnTypeExtension.php @@ -39,12 +39,14 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, $namesReturnType ); + $args = $functionCall->getArgs(); // Called without second $output arguments - if (count($functionCall->args) <= 1) { + + if (count($args) <= 1) { return $namesReturnType; } - $argumentType = $scope->getType($functionCall->args[1]->value); + $argumentType = $scope->getType($args[1]->value); // When called with a non-string $output, return default return type if (! $argumentType instanceof ConstantStringType) { diff --git a/src/IsWpErrorFunctionTypeSpecifyingExtension.php b/src/IsWpErrorFunctionTypeSpecifyingExtension.php index ef04d20..8cb7a99 100644 --- a/src/IsWpErrorFunctionTypeSpecifyingExtension.php +++ b/src/IsWpErrorFunctionTypeSpecifyingExtension.php @@ -35,7 +35,9 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n throw new \PHPStan\ShouldNotHappenException(); } - return $this->typeSpecifier->create($node->args[0]->value, new ObjectType('WP_Error'), $context); + $args = $node->getArgs(); + + return $this->typeSpecifier->create($args[0]->value, new ObjectType('WP_Error'), $context); } public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void diff --git a/src/MySQL2DateDynamicFunctionReturnTypeExtension.php b/src/MySQL2DateDynamicFunctionReturnTypeExtension.php index b2ab2e1..7b190a0 100644 --- a/src/MySQL2DateDynamicFunctionReturnTypeExtension.php +++ b/src/MySQL2DateDynamicFunctionReturnTypeExtension.php @@ -31,13 +31,14 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo */ public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { - $argumentType = $scope->getType($functionCall->args[0]->value); + $args = $functionCall->getArgs(); + $argumentType = $scope->getType($args[0]->value); // When called with a $format that isn't a constant string, return default return type if (! $argumentType instanceof ConstantStringType) { return ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->args, + $args, $functionReflection->getVariants() )->getReturnType(); } diff --git a/src/ShortcodeAttsDynamicFunctionReturnTypeExtension.php b/src/ShortcodeAttsDynamicFunctionReturnTypeExtension.php index 2264d8f..82f1784 100644 --- a/src/ShortcodeAttsDynamicFunctionReturnTypeExtension.php +++ b/src/ShortcodeAttsDynamicFunctionReturnTypeExtension.php @@ -26,15 +26,16 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { - if ($functionCall->args === []) { + $args = $functionCall->getArgs(); + if ($args === []) { return ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->args, + $args, $functionReflection->getVariants() )->getReturnType(); } - $type = $scope->getType($functionCall->args[0]->value); + $type = $scope->getType($args[0]->value); if ($type instanceof ConstantArrayType) { // shortcode_atts values are coming from the defined defaults or from the actual string shortcode attributes diff --git a/src/StringOrArrayDynamicFunctionReturnTypeExtension.php b/src/StringOrArrayDynamicFunctionReturnTypeExtension.php index 1fed58b..3bf986f 100644 --- a/src/StringOrArrayDynamicFunctionReturnTypeExtension.php +++ b/src/StringOrArrayDynamicFunctionReturnTypeExtension.php @@ -25,16 +25,17 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type { - $argsCount = count($functionCall->args); + $args = $functionCall->getArgs(); + $argsCount = count($args); if ($argsCount === 0) { return ParametersAcceptorSelector::selectFromArgs( $scope, - $functionCall->args, + $args, $functionReflection->getVariants() )->getReturnType(); } - $dataArg = $functionCall->args[0]->value; + $dataArg = $args[0]->value; $dataArgType = $scope->getType($dataArg); if ($dataArgType instanceof ArrayType) { $keyType = $dataArgType->getIterableKeyType();