| Total Complexity | 7 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Coverage | 78.95% |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | final class Request |
||
| 8 | { |
||
| 9 | public const METHOD_CONNECT = 'CONNECT'; |
||
| 10 | public const METHOD_DELETE = 'DELETE'; |
||
| 11 | public const METHOD_GET = 'GET'; |
||
| 12 | public const METHOD_HEAD = 'HEAD'; |
||
| 13 | public const METHOD_OPTIONS = 'OPTIONS'; |
||
| 14 | public const METHOD_PATCH = 'PATCH'; |
||
| 15 | public const METHOD_POST = 'POST'; |
||
| 16 | public const METHOD_PUT = 'PUT'; |
||
| 17 | public const METHOD_TRACE = 'TRACE'; |
||
| 18 | private static ?self $instance = null; |
||
| 19 | |||
| 20 | 42 | private function __construct( |
|
| 21 | private array $query, |
||
| 22 | private array $request, |
||
| 23 | private array $server, |
||
| 24 | ) { |
||
| 25 | 42 | } |
|
| 26 | |||
| 27 | 42 | public static function resetCache(): void |
|
| 28 | { |
||
| 29 | 42 | self::$instance = null; |
|
| 30 | } |
||
| 31 | |||
| 32 | 42 | public static function instance(): self |
|
| 33 | { |
||
| 34 | 42 | if (self::$instance === null) { |
|
| 35 | 42 | self::$instance = new self($_GET, $_POST, $_SERVER); |
|
| 36 | } |
||
| 37 | 42 | return self::$instance; |
|
|
|
|||
| 38 | } |
||
| 39 | |||
| 40 | 42 | public function isMethod(string $method): bool |
|
| 41 | { |
||
| 42 | /** @psalm-suppress PossiblyUndefinedArrayOffset */ |
||
| 43 | 42 | return (string)$this->server['REQUEST_METHOD'] === $method; |
|
| 44 | } |
||
| 45 | |||
| 46 | 41 | public function path(): string |
|
| 52 | 41 | ); |
|
| 53 | } |
||
| 54 | |||
| 55 | public function get(string $key): mixed |
||
| 56 | { |
||
| 62 |