| Total Complexity | 13 |
| Total Lines | 63 |
| Duplicated Lines | 0 % |
| Coverage | 61.53% |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 12 | final class HttpHeaderBag implements Iterator |
||
| 13 | { |
||
| 14 | /** @var HttpHeader[] */ |
||
| 15 | private $headers = []; |
||
| 16 | |||
| 17 | 2 | public function add(HttpHeader $headerValue) |
|
| 18 | { |
||
| 19 | 2 | $this->headers[] = $headerValue; |
|
| 20 | 2 | } |
|
| 21 | |||
| 22 | 2 | public function has(string $headerName): bool |
|
| 23 | { |
||
| 24 | 2 | foreach ($this->headers as $header) { |
|
| 25 | 2 | if ($header->name() === $headerName) { |
|
| 26 | 1 | return true; |
|
| 27 | } |
||
| 28 | } |
||
| 29 | |||
| 30 | 2 | return false; |
|
| 31 | } |
||
| 32 | |||
| 33 | public function get(string $headerName): array |
||
| 34 | { |
||
| 35 | $headers = []; |
||
| 36 | |||
| 37 | foreach ($this->headers as $header) { |
||
| 38 | if ($header->name() === $headerName) { |
||
| 39 | $headers[] = $header; |
||
| 40 | } |
||
| 41 | } |
||
| 42 | |||
| 43 | return $headers; |
||
| 44 | } |
||
| 45 | |||
| 46 | public function getFirst(string $headerName): HttpHeader |
||
| 47 | { |
||
| 48 | return $this->get($headerName)[0]; |
||
| 49 | } |
||
| 50 | |||
| 51 | /** @return HttpHeader|bool */ |
||
| 52 | 2 | public function current() |
|
| 53 | { |
||
| 54 | 2 | return current($this->headers); |
|
| 55 | } |
||
| 56 | |||
| 57 | 2 | public function next() |
|
| 58 | { |
||
| 59 | 2 | return next($this->headers); |
|
| 60 | } |
||
| 61 | |||
| 62 | public function key() |
||
| 63 | { |
||
| 64 | return key($this->headers); |
||
| 65 | } |
||
| 66 | |||
| 67 | 2 | public function valid() |
|
| 68 | { |
||
| 69 | 2 | return $this->current() !== false; |
|
| 70 | } |
||
| 71 | |||
| 72 | 2 | public function rewind() |
|
| 75 | 2 | } |
|
| 76 | } |
||
| 77 |