Total Complexity | 4 |
Total Lines | 35 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
14 | final class AssistedWebContextParam implements ParamInterface |
||
15 | { |
||
16 | /** |
||
17 | * $GLOBALS for testing |
||
18 | * |
||
19 | * @var array<string, array<string, mixed>> |
||
20 | */ |
||
21 | private static array $globals = []; |
||
22 | |||
23 | public function __construct( |
||
24 | private readonly AbstractWebContextParam $webContextParam, |
||
25 | private readonly ParamInterface $defaultParam, |
||
26 | ) { |
||
27 | } |
||
28 | |||
29 | 5 | /** |
|
30 | * {@inheritDoc} |
||
31 | 5 | */ |
|
32 | 5 | #[Override] |
|
33 | 5 | public function __invoke(string $varName, array $query, InjectorInterface $injector) |
|
34 | { |
||
35 | $superGlobals = static::$globals ?: $GLOBALS; |
||
|
|||
36 | /** @var array<string, array<string, string>> $superGlobals */ |
||
37 | $webContextParam = $this->webContextParam; |
||
38 | 4 | assert(is_string($webContextParam::GLOBAL_KEY)); |
|
39 | /** @psalm-suppress MixedArrayOffset */ |
||
40 | 4 | $phpWebContext = $superGlobals[$webContextParam::GLOBAL_KEY]; |
|
41 | 4 | ||
42 | 4 | return $phpWebContext[$this->webContextParam->key] ?? ($this->defaultParam)($varName, $query, $injector); |
|
43 | } |
||
44 | 4 | ||
45 | 2 | /** @param array<string, array<string, mixed>> $globals */ |
|
46 | public static function setSuperGlobalsOnlyForTestingPurpose(array $globals): void |
||
49 | } |
||
50 | } |
||
51 |