Skip to content

Commit d44b5ab

Browse files
authored
Merge pull request #87 from johnbillion/php-parser
2 parents f082ca2 + cbdc4e5 commit d44b5ab

12 files changed

+46
-31
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"require-dev": {
2020
"composer/composer": "^1.10.23",
2121
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
22-
"nikic/php-parser": "< 4.13.0",
2322
"php-parallel-lint/php-parallel-lint": "^1.1",
2423
"phpstan/phpstan-strict-rules": "^1.0",
2524
"phpunit/phpunit": "^7 || ^9",

src/CurrentTimeDynamicFunctionReturnTypeExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,14 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
2929
*/
3030
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
3131
{
32-
$argumentType = $scope->getType($functionCall->args[0]->value);
32+
$args = $functionCall->getArgs();
33+
$argumentType = $scope->getType($args[0]->value);
3334

3435
// When called with a $type that isn't a constant string, return default return type
3536
if (! $argumentType instanceof ConstantStringType) {
3637
return ParametersAcceptorSelector::selectFromArgs(
3738
$scope,
38-
$functionCall->args,
39+
$args,
3940
$functionReflection->getVariants()
4041
)->getReturnType();
4142
}

src/GetCommentDynamicFunctionReturnTypeExtension.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,23 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
3434
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
3535
{
3636
$output = 'OBJECT';
37+
$args = $functionCall->getArgs();
3738

38-
if (count($functionCall->args) >= 2) {
39-
$argumentType = $scope->getType($functionCall->args[1]->value);
39+
if (count($args) >= 2) {
40+
$argumentType = $scope->getType($args[1]->value);
4041

4142
// When called with an $output that isn't a constant string, return default return type
4243
if (! $argumentType instanceof ConstantStringType) {
4344
return ParametersAcceptorSelector::selectFromArgs(
4445
$scope,
45-
$functionCall->args,
46+
$args,
4647
$functionReflection->getVariants()
4748
)->getReturnType();
4849
}
4950
}
5051

51-
if (count($functionCall->args) >= 2 && $functionCall->args[1]->value instanceof ConstFetch) {
52-
$output = $functionCall->args[1]->value->name->getLast();
52+
if (count($args) >= 2 && $args[1]->value instanceof ConstFetch) {
53+
$output = $args[1]->value->name->getLast();
5354
}
5455
if ($output === 'ARRAY_A') {
5556
return TypeCombinator::union(new ArrayType(new StringType(), new MixedType()), new NullType());

src/GetListTableDynamicFunctionReturnTypeExtension.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,20 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
2828
// phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter
2929
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
3030
{
31+
$args = $functionCall->getArgs();
32+
3133
// Called without $class argument
32-
if (count($functionCall->args) < 1) {
34+
if (count($args) < 1) {
3335
return new ConstantBooleanType(false);
3436
}
3537

36-
$argumentType = $scope->getType($functionCall->args[0]->value);
38+
$argumentType = $scope->getType($args[0]->value);
3739

3840
// When called with a $class that isn't a constant string, return default return type
3941
if (! $argumentType instanceof ConstantStringType) {
4042
return ParametersAcceptorSelector::selectFromArgs(
4143
$scope,
42-
$functionCall->args,
44+
$args,
4345
$functionReflection->getVariants()
4446
)->getReturnType();
4547
}

src/GetObjectTaxonomiesDynamicFunctionReturnTypeExtension.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,20 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
3333
*/
3434
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
3535
{
36+
$args = $functionCall->getArgs();
37+
3638
// Called without second $output argument
37-
if (count($functionCall->args) <= 1) {
39+
if (count($args) <= 1) {
3840
return new ArrayType(new IntegerType(), new StringType());
3941
}
4042

41-
$argumentType = $scope->getType($functionCall->args[1]->value);
43+
$argumentType = $scope->getType($args[1]->value);
4244

4345
// When called with an $output that isn't a constant string, return default return type
4446
if (! $argumentType instanceof ConstantStringType) {
4547
return ParametersAcceptorSelector::selectFromArgs(
4648
$scope,
47-
$functionCall->args,
49+
$args,
4850
$functionReflection->getVariants()
4951
)->getReturnType();
5052
}

src/GetPostDynamicFunctionReturnTypeExtension.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,23 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
3434
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
3535
{
3636
$output = 'OBJECT';
37+
$args = $functionCall->getArgs();
3738

3839
if (count($functionCall->args) >= 2) {
39-
$argumentType = $scope->getType($functionCall->args[1]->value);
40+
$argumentType = $scope->getType($args[1]->value);
4041

4142
// When called with an $output that isn't a constant string, return default return type
4243
if (! $argumentType instanceof ConstantStringType) {
4344
return ParametersAcceptorSelector::selectFromArgs(
4445
$scope,
45-
$functionCall->args,
46+
$args,
4647
$functionReflection->getVariants()
4748
)->getReturnType();
4849
}
4950
}
5051

51-
if (count($functionCall->args) >= 2 && $functionCall->args[1]->value instanceof ConstFetch) {
52-
$output = $functionCall->args[1]->value->name->getLast();
52+
if (count($args) >= 2 && $args[1]->value instanceof ConstFetch) {
53+
$output = $args[1]->value->name->getLast();
5354
}
5455
if ($output === 'ARRAY_A') {
5556
return TypeCombinator::union(new ArrayType(new StringType(), new MixedType()), new NullType());

src/GetPostsDynamicFunctionReturnTypeExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
3131
// phpcs:ignore SlevomatCodingStandard.Functions.UnusedParameter
3232
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
3333
{
34+
$args = $functionCall->getArgs();
35+
3436
// Called without arguments
35-
if (count($functionCall->args) === 0) {
37+
if (count($args) === 0) {
3638
return new ArrayType(new IntegerType(), new ObjectType('WP_Post'));
3739
}
3840

39-
$argumentType = $scope->getType($functionCall->args[0]->value);
41+
$argumentType = $scope->getType($args[0]->value);
4042

4143
// Called with an array argument
4244
if ($argumentType instanceof ConstantArrayType) {

src/GetTaxonomiesDynamicFunctionReturnTypeExtension.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,14 @@ public function getTypeFromFunctionCall(FunctionReflection $functionReflection,
3939
$namesReturnType
4040
);
4141

42+
$args = $functionCall->getArgs();
4243
// Called without second $output arguments
43-
if (count($functionCall->args) <= 1) {
44+
45+
if (count($args) <= 1) {
4446
return $namesReturnType;
4547
}
4648

47-
$argumentType = $scope->getType($functionCall->args[1]->value);
49+
$argumentType = $scope->getType($args[1]->value);
4850

4951
// When called with a non-string $output, return default return type
5052
if (! $argumentType instanceof ConstantStringType) {

src/IsWpErrorFunctionTypeSpecifyingExtension.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public function specifyTypes(FunctionReflection $functionReflection, FuncCall $n
3535
throw new \PHPStan\ShouldNotHappenException();
3636
}
3737

38-
return $this->typeSpecifier->create($node->args[0]->value, new ObjectType('WP_Error'), $context);
38+
$args = $node->getArgs();
39+
40+
return $this->typeSpecifier->create($args[0]->value, new ObjectType('WP_Error'), $context);
3941
}
4042

4143
public function setTypeSpecifier(TypeSpecifier $typeSpecifier): void

src/MySQL2DateDynamicFunctionReturnTypeExtension.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
3131
*/
3232
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
3333
{
34-
$argumentType = $scope->getType($functionCall->args[0]->value);
34+
$args = $functionCall->getArgs();
35+
$argumentType = $scope->getType($args[0]->value);
3536

3637
// When called with a $format that isn't a constant string, return default return type
3738
if (! $argumentType instanceof ConstantStringType) {
3839
return ParametersAcceptorSelector::selectFromArgs(
3940
$scope,
40-
$functionCall->args,
41+
$args,
4142
$functionReflection->getVariants()
4243
)->getReturnType();
4344
}

0 commit comments

Comments
 (0)