15
15
use PHPStan \Type \DynamicMethodReturnTypeExtension ;
16
16
use PHPStan \Type \ObjectType ;
17
17
use PHPStan \Type \Type ;
18
+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBag ;
18
19
use function in_array ;
19
- use function is_scalar ;
20
- use function strpos ;
21
- use function trim ;
22
20
23
21
final class ServiceDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
24
22
{
@@ -32,8 +30,8 @@ final class ServiceDynamicReturnTypeExtension implements DynamicMethodReturnType
32
30
/** @var ServiceMap */
33
31
private $ serviceMap ;
34
32
35
- /** @var ParameterMap */
36
- private $ parameterMap ;
33
+ /** @var ParameterBag */
34
+ private $ parameterBag ;
37
35
38
36
public function __construct (
39
37
string $ className ,
@@ -45,7 +43,7 @@ public function __construct(
45
43
$ this ->className = $ className ;
46
44
$ this ->constantHassers = $ configuration ->hasConstantHassers ();
47
45
$ this ->serviceMap = $ symfonyServiceMap ;
48
- $ this ->parameterMap = $ symfonyParameterMap ;
46
+ $ this ->parameterBag = $ this -> createParameterBag ( $ symfonyParameterMap) ;
49
47
}
50
48
51
49
public function getClass (): string
@@ -113,17 +111,18 @@ private function getHasTypeFromMethodCall(
113
111
114
112
private function determineServiceClass (ServiceDefinition $ service ): ?string
115
113
{
116
- $ class = $ service ->getClass ();
114
+ return $ this ->parameterBag ->resolveValue ($ service ->getClass ());
115
+ }
117
116
118
- if ($ class !== null && strpos ($ class , '% ' ) === 0 ) {
119
- $ param = $ this ->parameterMap ->getParameter (trim ($ class , '% ' ));
117
+ private function createParameterBag (ParameterMap $ symfonyParameterMap ): ParameterBag
118
+ {
119
+ $ parameters = [];
120
120
121
- if ($ param !== null && is_scalar ($ param ->getValue ())) {
122
- return (string ) $ param ->getValue ();
123
- }
121
+ foreach ($ symfonyParameterMap ->getParameters () as $ parameterDefinition ) {
122
+ $ parameters [$ parameterDefinition ->getKey ()] = $ parameterDefinition ->getValue ();
124
123
}
125
124
126
- return $ class ;
125
+ return new ParameterBag ( $ parameters ) ;
127
126
}
128
127
129
128
}
0 commit comments