forked from phpstan/phpstan-symfony
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLazyParameterMap.php
More file actions
58 lines (43 loc) · 1.41 KB
/
LazyParameterMap.php
File metadata and controls
58 lines (43 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php declare(strict_types = 1);
namespace PHPStan\Symfony;
use PhpParser\Node\Expr;
use PHPStan\Analyser\Scope;
abstract class LazyParameterMap implements ParameterMap
{
private function __construct()
{
}
final public static function create(ParameterMapFactory $parameterMapFactory): self
{
// Workaround to make the static method getParameterKeysFromNode() work without sharing state across all LazyParameterMap instances
$lazyParameterMap = new class () extends LazyParameterMap
{
protected static ParameterMapFactory $parameterMapFactory;
protected static ?ParameterMap $parameterMap;
protected static function getParameterMap(): ParameterMap
{
self::$parameterMap ??= self::$parameterMapFactory->create();
return self::$parameterMap;
}
};
$lazyParameterMap::$parameterMapFactory = $parameterMapFactory;
$lazyParameterMap::$parameterMap = null;
return $lazyParameterMap;
}
abstract protected static function getParameterMap(): ParameterMap;
/**
* @return ParameterDefinition[]
*/
public function getParameters(): array
{
return static::getParameterMap()->getParameters();
}
public function getParameter(string $key): ?ParameterDefinition
{
return static::getParameterMap()->getParameter($key);
}
public static function getParameterKeysFromNode(Expr $node, Scope $scope): array
{
return static::getParameterMap()::getParameterKeysFromNode($node, $scope);
}
}