Passed
Push — coroutine-safe ( 24bd87 )
by Akihito
02:44
created

GlobalServerContext::has()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\QueryRepository;
6
7
use Override;
8
9
use function is_string;
10
11
/**
12
 * Server context implementation using $_SERVER superglobal
13
 *
14
 * This is the default implementation for traditional PHP-FPM environments
15
 * where each request runs in isolation and $_SERVER is safe to use.
16
 *
17
 * For concurrent request processing (Swoole, RoadRunner), use a request-scoped
18
 * implementation instead.
19
 */
20
final class GlobalServerContext implements ServerContextInterface
21
{
22
    #[Override]
23
    public function get(string $key): string|null
24
    {
25
        if (! isset($_SERVER[$key])) {
26
            return null;
27
        }
28
29
        /** @var mixed $value */
30
        $value = $_SERVER[$key];
31
32
        return is_string($value) ? $value : null;
33
    }
34
35
    #[Override]
36
    public function has(string $key): bool
37
    {
38
        return isset($_SERVER[$key]);
39
    }
40
}
41