Skip to content

Commit f4654b2

Browse files
committed
Improve compatibility with nikic/php-parser 4.13.0
1 parent 7c73ca8 commit f4654b2

9 files changed

+18
-22
lines changed

src/Type/Nette/ComponentGetPresenterDynamicReturnTypeExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
3232
$defaultReturnType = $methodDefinition->getReturnType();
3333
$firstParameterExists = count($methodDefinition->getParameters()) > 0;
3434

35-
if (count($methodCall->args) < 1) {
35+
if (count($methodCall->getArgs()) < 1) {
3636
if (!$firstParameterExists) {
3737
return TypeCombinator::removeNull($defaultReturnType);
3838
}
3939

4040
return $defaultReturnType;
4141
}
4242

43-
$paramNeedExpr = $methodCall->args[0]->value;
43+
$paramNeedExpr = $methodCall->getArgs()[0]->value;
4444
$paramNeedType = $scope->getType($paramNeedExpr);
4545

4646
if ($paramNeedType instanceof ConstantBooleanType) {

src/Type/Nette/ComponentLookupDynamicReturnTypeExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
2929
$defaultReturnType = ParametersAcceptorSelector::selectSingle(
3030
$methodReflection->getVariants()
3131
)->getReturnType();
32-
if (count($methodCall->args) < 2) {
32+
if (count($methodCall->getArgs()) < 2) {
3333
return $defaultReturnType;
3434
}
3535

36-
$paramNeedExpr = $methodCall->args[1]->value;
36+
$paramNeedExpr = $methodCall->getArgs()[1]->value;
3737
$paramNeedType = $scope->getType($paramNeedExpr);
3838

3939
if ($paramNeedType instanceof ConstantBooleanType) {

src/Type/Nette/ComponentModelArrayAccessDynamicReturnTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getTypeFromMethodCall(
3434
{
3535
$calledOnType = $scope->getType($methodCall->var);
3636
$mixedType = new MixedType();
37-
$args = $methodCall->args;
37+
$args = $methodCall->getArgs();
3838
if (count($args) !== 1) {
3939
return $mixedType;
4040
}

src/Type/Nette/ComponentModelDynamicReturnTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function getTypeFromMethodCall(
3434
{
3535
$calledOnType = $scope->getType($methodCall->var);
3636
$mixedType = new MixedType();
37-
$args = $methodCall->args;
37+
$args = $methodCall->getArgs();
3838
if (count($args) !== 1) {
3939
return $mixedType;
4040
}

src/Type/Nette/FormContainerUnsafeValuesDynamicReturnTypeExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
3030

3131
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
3232
{
33-
if (count($methodCall->args) === 0) {
33+
if (count($methodCall->getArgs()) === 0) {
3434
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
3535
}
3636

37-
$arg = $methodCall->args[0]->value;
37+
$arg = $methodCall->getArgs()[0]->value;
3838
$scopedType = $scope->getType($arg);
3939
if ($scopedType instanceof NullType) {
4040
return new ObjectType('Nette\Utils\ArrayHash');

src/Type/Nette/FormContainerValuesDynamicReturnTypeExtension.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2929

3030
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
3131
{
32-
if (count($methodCall->args) === 0) {
32+
if (count($methodCall->getArgs()) === 0) {
3333
return new ObjectType('Nette\Utils\ArrayHash');
3434
}
3535

36-
$arg = $methodCall->args[0]->value;
36+
$arg = $methodCall->getArgs()[0]->value;
3737
$scopedType = $scope->getType($arg);
3838
if (!$scopedType instanceof ConstantBooleanType) {
3939
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();

src/Type/Nette/PresenterGetSessionReturnTypeExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function isMethodSupported(MethodReflection $methodReflection): bool
2525

2626
public function getTypeFromMethodCall(MethodReflection $methodReflection, MethodCall $methodCall, Scope $scope): Type
2727
{
28-
if (count($methodCall->args) === 0 || $scope->getType($methodCall->args[0]->value) instanceof NullType) {
28+
if (count($methodCall->getArgs()) === 0 || $scope->getType($methodCall->getArgs()[0]->value) instanceof NullType) {
2929
return new ObjectType('Nette\Http\Session');
3030
}
3131

src/Type/Nette/ServiceLocatorDynamicReturnTypeExtension.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@ public function getTypeFromMethodCall(MethodReflection $methodReflection, Method
3939
], true)) {
4040
return $mixedType;
4141
}
42-
if (count($methodCall->args) === 0) {
42+
if (count($methodCall->getArgs()) === 0) {
4343
return $mixedType;
4444
}
45-
$argType = $scope->getType($methodCall->args[0]->value);
45+
$argType = $scope->getType($methodCall->getArgs()[0]->value);
4646
if (!$argType instanceof ConstantStringType) {
4747
return $mixedType;
4848
}
4949

5050
$type = new ObjectType($argType->getValue());
5151
if (
5252
$methodReflection->getName() === 'getByType'
53-
&& count($methodCall->args) >= 2
53+
&& count($methodCall->getArgs()) >= 2
5454
) {
55-
$throwType = $scope->getType($methodCall->args[1]->value);
55+
$throwType = $scope->getType($methodCall->getArgs()[1]->value);
5656
if (
5757
!$throwType instanceof ConstantBooleanType
5858
|| !$throwType->getValue()

tests/Type/Nette/FormContainerValuesDynamicReturnTypeExtensionTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,14 @@ public function testParameterAsArray(): void
4444
$scope = $this->createMock(Scope::class);
4545
$scope->method('getType')->willReturn(new ConstantBooleanType(true));
4646

47-
/** @var \PhpParser\Node\Expr\MethodCall $methodCall */
4847
$methodCall = $this->createMock(MethodCall::class);
49-
/** @var \PhpParser\Node\Arg $arg */
5048
$arg = $this->createMock(Arg::class);
51-
/** @var \PhpParser\Node\Expr $value */
5249
$value = $this->createMock(Expr::class);
5350
$arg->value = $value;
5451
$methodCall->args = [
5552
0 => $arg,
5653
];
54+
$methodCall->method('getArgs')->willReturn($methodCall->args);
5755

5856
$resultType = $this->extension->getTypeFromMethodCall($methodReflection, $methodCall, $scope);
5957

@@ -70,16 +68,14 @@ public function testParameterAsArrayHash(): void
7068
$scope = $this->createMock(Scope::class);
7169
$scope->method('getType')->willReturn(new ConstantBooleanType(false));
7270

73-
/** @var \PhpParser\Node\Expr\MethodCall $methodCall */
7471
$methodCall = $this->createMock(MethodCall::class);
75-
/** @var \PhpParser\Node\Arg $arg */
7672
$arg = $this->createMock(Arg::class);
77-
/** @var \PhpParser\Node\Expr $value */
7873
$value = $this->createMock(Expr::class);
7974
$arg->value = $value;
8075
$methodCall->args = [
8176
0 => $arg,
8277
];
78+
$methodCall->method('getArgs')->willReturn($methodCall->args);
8379

8480
$resultType = $this->extension->getTypeFromMethodCall($methodReflection, $methodCall, $scope);
8581

@@ -97,9 +93,9 @@ public function testDefaultParameterIsArrayHash(): void
9793
$scope = $this->createMock(Scope::class);
9894
$scope->method('getType')->willReturn(new ConstantBooleanType(false));
9995

100-
/** @var \PhpParser\Node\Expr\MethodCall $methodCall */
10196
$methodCall = $this->createMock(MethodCall::class);
10297
$methodCall->args = [];
98+
$methodCall->method('getArgs')->willReturn($methodCall->args);
10399

104100
$resultType = $this->extension->getTypeFromMethodCall($methodReflection, $methodCall, $scope);
105101

0 commit comments

Comments
 (0)