-
Notifications
You must be signed in to change notification settings - Fork 574
Expand file tree
/
Copy pathParameterAllowedConstantsMapProvider.php
More file actions
50 lines (38 loc) · 1.44 KB
/
ParameterAllowedConstantsMapProvider.php
File metadata and controls
50 lines (38 loc) · 1.44 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
<?php declare(strict_types = 1);
namespace PHPStan\Reflection;
use PHPStan\DependencyInjection\AutowiredService;
#[AutowiredService]
final class ParameterAllowedConstantsMapProvider
{
/** @var array<string, array<string, array{type: string, constants: list<string>, exclusiveGroups?: list<list<string>>}>>|null */
private ?array $map = null;
public function getForFunctionParameter(string $functionName, string $parameterName): ?ParameterAllowedConstants
{
return $this->get($functionName, $parameterName);
}
public function getForMethodParameter(string $className, string $methodName, string $parameterName): ?ParameterAllowedConstants
{
return $this->get($className . '::' . $methodName, $parameterName);
}
private function get(string $key, string $parameterName): ?ParameterAllowedConstants
{
$map = $this->getMap();
if (!isset($map[$key][$parameterName])) {
return null;
}
/** @var array{type: 'single'|'bitmask', constants: list<string>, exclusiveGroups?: list<list<string>>} $config */
$config = $map[$key][$parameterName];
return new ParameterAllowedConstants(
$config['type'],
$config['constants'],
$config['exclusiveGroups'] ?? [],
);
}
/**
* @return array<string, array<string, array{type: string, constants: list<string>, exclusiveGroups?: list<list<string>>}>>
*/
private function getMap(): array
{
return $this->map ??= require __DIR__ . '/../../resources/constantToFunctionParameterMap.php';
}
}