4
4
5
5
use PhpParser \Node \Expr \MethodCall ;
6
6
use PHPStan \Analyser \Scope ;
7
+ use PHPStan \PhpDoc \TypeStringResolver ;
7
8
use PHPStan \Reflection \MethodReflection ;
8
9
use PHPStan \Reflection \ParametersAcceptorSelector ;
9
10
use PHPStan \ShouldNotHappenException ;
25
26
use PHPStan \Type \TypeCombinator ;
26
27
use PHPStan \Type \TypeTraverser ;
27
28
use PHPStan \Type \UnionType ;
29
+ use Symfony \Component \DependencyInjection \EnvVarProcessor ;
28
30
use function in_array ;
29
31
30
32
final class ParameterDynamicReturnTypeExtension implements DynamicMethodReturnTypeExtension
@@ -45,13 +47,24 @@ final class ParameterDynamicReturnTypeExtension implements DynamicMethodReturnTy
45
47
/** @var \PHPStan\Symfony\ParameterMap */
46
48
private $ parameterMap ;
47
49
48
- public function __construct (string $ className , ?string $ methodGet , ?string $ methodHas , Configuration $ configuration , ParameterMap $ symfonyParameterMap )
50
+ /** @var \PHPStan\PhpDoc\TypeStringResolver */
51
+ private $ typeStringResolver ;
52
+
53
+ public function __construct (
54
+ string $ className ,
55
+ ?string $ methodGet ,
56
+ ?string $ methodHas ,
57
+ Configuration $ configuration ,
58
+ ParameterMap $ symfonyParameterMap ,
59
+ TypeStringResolver $ typeStringResolver
60
+ )
49
61
{
50
62
$ this ->className = $ className ;
51
63
$ this ->methodGet = $ methodGet ;
52
64
$ this ->methodHas = $ methodHas ;
53
65
$ this ->constantHassers = $ configuration ->hasConstantHassers ();
54
66
$ this ->parameterMap = $ symfonyParameterMap ;
67
+ $ this ->typeStringResolver = $ typeStringResolver ;
55
68
}
56
69
57
70
public function getClass (): string
@@ -134,33 +147,9 @@ private function generalizeTypeFromValue(Scope $scope, $value): Type
134
147
&& preg_match ('/%env\((.*)\:.*\)%/U ' , $ value , $ matches ) === 1
135
148
&& strlen ($ matches [0 ]) === strlen ($ value )
136
149
) {
137
- switch ($ matches [1 ]) {
138
- case 'base64 ' :
139
- case 'file ' :
140
- case 'resolve ' :
141
- case 'string ' :
142
- case 'trim ' :
143
- return new StringType ();
144
- case 'bool ' :
145
- return new BooleanType ();
146
- case 'int ' :
147
- return new IntegerType ();
148
- case 'float ' :
149
- return new FloatType ();
150
- case 'csv ' :
151
- case 'json ' :
152
- case 'url ' :
153
- case 'query_string ' :
154
- return new ArrayType (new MixedType (), new MixedType ());
155
- default :
156
- return new UnionType ([
157
- new ArrayType (new MixedType (), new MixedType ()),
158
- new BooleanType (),
159
- new FloatType (),
160
- new IntegerType (),
161
- new StringType (),
162
- ]);
163
- }
150
+ $ providedTypes = EnvVarProcessor::getProvidedTypes ();
151
+
152
+ return $ this ->typeStringResolver ->resolve ($ providedTypes [$ matches [1 ]] ?? 'bool|int|float|string|array ' );
164
153
}
165
154
166
155
return $ this ->generalizeType ($ scope ->getTypeFromValue ($ value ));
0 commit comments