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