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

ParsedHeaderBag   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 12%

Importance

Changes 0
Metric Value
wmc 11
eloc 17
dl 0
loc 59
c 0
b 0
f 0
ccs 3
cts 25
cp 0.12
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A next() 0 3 1
A current() 0 3 1
A findOne() 0 9 2
A key() 0 3 1
A add() 0 3 1
A findMultiple() 0 11 3
A valid() 0 3 1
A rewind() 0 3 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\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