Skip to content

Commit 5c80488

Browse files
staabmkayw-geek
andauthored
Trigger reflection processing lazily (#64)
Co-authored-by: Kay W. <[email protected]>
1 parent 1b231d1 commit 5c80488

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Type/Php/JsonDecodeDynamicReturnTypeExtension.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@
1818
*/
1919
final class JsonDecodeDynamicReturnTypeExtension implements DynamicFunctionReturnTypeExtension
2020
{
21-
private FunctionReflection $nativeJsonDecodeReflection;
21+
private ?FunctionReflection $nativeJsonDecodeReflection = null;
2222

2323
public function __construct(
2424
private readonly JsonThrowOnErrorDynamicReturnTypeExtension $phpstanCheck,
25-
ReflectionProvider $reflectionProvider,
25+
private readonly ReflectionProvider $reflectionProvider,
2626
) {
27-
$this->nativeJsonDecodeReflection = $reflectionProvider->getFunction(new Name('json_decode'), null);
2827
}
2928

3029
public function isFunctionSupported(FunctionReflection $functionReflection): bool
@@ -34,6 +33,10 @@ public function isFunctionSupported(FunctionReflection $functionReflection): boo
3433

3534
public function getTypeFromFunctionCall(FunctionReflection $functionReflection, FuncCall $functionCall, Scope $scope): Type
3635
{
36+
// trigger reflection processing lazily.
37+
if ($this->nativeJsonDecodeReflection === null) {
38+
$this->nativeJsonDecodeReflection = $this->reflectionProvider->getFunction(new Name('json_decode'), null);
39+
}
3740
$result = $this->phpstanCheck->getTypeFromFunctionCall($this->nativeJsonDecodeReflection, $functionCall, $scope);
3841

3942
// if PHPStan reports null and there is a json error, then an invalid constant string was passed

0 commit comments

Comments
 (0)