Completed
Branch master (016f5c)
by Nico
02:23 queued 01:03
created

ParsedHeaderBag::current()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
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\Result;
9
10
use Iterator;
11
12
final class ParsedHeaderBag implements Iterator
13
{
14
    /** @var AbstractParsedHeader[] */
15
    private $headers = [];
16
17 2
    public function add(AbstractParsedHeader $header): void
18
    {
19 2
        $this->headers[] = $header;
20 2
    }
21
22
    /** @return AbstractParsedHeader[] */
23
    public function findMultiple(string $name): array
24
    {
25
        $headers = [];
26
27
        foreach ($this->headers as $header) {
28
            if ($header->name() === $name) {
29
                $headers[] = $header;
30
            }
31
        }
32
33
        return $headers;
34
    }
35
36
    public function findOne(string $name): ?AbstractParsedHeader
37
    {
38
        $headers = $this->findMultiple($name);
39
40
        if (count($headers) === 1) {
41
            return $headers[0];
42
        }
43
44
        return null;
45
    }
46
47
    /** @return AbstractParsedHeader */
48
    public function current()
49
    {
50
        return current($this->headers);
51
    }
52
53
    public function next()
54
    {
55
        next($this->headers);
56
    }
57
58
    public function key()
59
    {
60
        return key($this->headers);
61
    }
62
63
    public function valid()
64
    {
65
        return $this->current() !== false;
66
    }
67
68
    public function rewind()
69
    {
70
        reset($this->headers);
71
    }
72
}
73