Completed
Push — master ( 1ba115...baab82 )
by Nico
02:35
created

HttpHeaderBag::valid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * @license  http://opensource.org/licenses/mit-license.php MIT
5
 * @link     https://github.com/nicoSWD
6
 * @author   Nicolas Oelgart <[email protected]>
7
 */
8
namespace nicoSWD\SecHeaderCheck\Domain\Header;
9
10
use Iterator;
11
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()
73
    {
74 2
        reset($this->headers);
75 2
    }
76
}
77