Skip to content

Commit 24d8c15

Browse files
committed
Fix compatibility with Symfony 7.4/8.0 - fix Call to method arrayNode() on an unknown class
1 parent df675ec commit 24d8c15

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/Type/Symfony/Config/ArrayNodeDefinitionPrototypeDynamicReturnTypeExtension.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1010
use PHPStan\Type\Symfony\Config\ValueObject\ParentObjectType;
1111
use PHPStan\Type\Type;
12-
use PHPStan\Type\VerbosityLevel;
1312
use function count;
1413
use function in_array;
1514

@@ -50,7 +49,7 @@ public function getTypeFromMethodCall(
5049
MethodReflection $methodReflection,
5150
MethodCall $methodCall,
5251
Scope $scope
53-
): Type
52+
): ?Type
5453
{
5554
$calledOnType = $scope->getType($methodCall->var);
5655

@@ -73,8 +72,13 @@ public function getTypeFromMethodCall(
7372
}
7473
}
7574

75+
$classNames = $defaultType->getObjectClassNames();
76+
if (count($classNames) !== 1) {
77+
return null;
78+
}
79+
7680
return new ParentObjectType(
77-
$defaultType->describe(VerbosityLevel::typeOnly()),
81+
$classNames[0],
7882
$calledOnType,
7983
);
8084
}

src/Type/Symfony/Config/PassParentObjectDynamicReturnTypeExtension.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use PHPStan\Type\DynamicMethodReturnTypeExtension;
1010
use PHPStan\Type\Symfony\Config\ValueObject\ParentObjectType;
1111
use PHPStan\Type\Type;
12-
use PHPStan\Type\VerbosityLevel;
12+
use function count;
1313
use function in_array;
1414

1515
final class PassParentObjectDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
@@ -45,7 +45,7 @@ public function getTypeFromMethodCall(
4545
MethodReflection $methodReflection,
4646
MethodCall $methodCall,
4747
Scope $scope
48-
): Type
48+
): ?Type
4949
{
5050
$calledOnType = $scope->getType($methodCall->var);
5151

@@ -55,7 +55,12 @@ public function getTypeFromMethodCall(
5555
$methodReflection->getVariants(),
5656
)->getReturnType();
5757

58-
return new ParentObjectType($defaultType->describe(VerbosityLevel::typeOnly()), $calledOnType);
58+
$classNames = $defaultType->getObjectClassNames();
59+
if (count($classNames) !== 1) {
60+
return null;
61+
}
62+
63+
return new ParentObjectType($classNames[0], $calledOnType);
5964
}
6065

6166
}

0 commit comments

Comments
 (0)