Completed
Pull Request — develop (#2)
by Sebastian
02:16
created

HeaderCollection   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 9
lcom 0
cbo 5
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A addHeader() 0 4 1
A current() 0 4 1
A getHeader() 0 10 3
A headerKeyExists() 0 8 2
A headerExists() 0 10 2
1
<?php
2
namespace DjThossi\SmokeTestingPhp\Collection;
3
4
use DjThossi\SmokeTestingPhp\ValueObject\Header;
5
use DjThossi\SmokeTestingPhp\ValueObject\HeaderKey;
6
7
class HeaderCollection extends BaseCollection
8
{
9
    /**
10
     * @param Header $header
11
     */
12
    public function addHeader(Header $header)
13
    {
14
        $this->addElement($header);
15
    }
16
17
    /**
18
     * @return Header
19
     */
20
    public function current()
21
    {
22
        return $this->getCurrent();
23
    }
24
25
    /**
26
     * @param HeaderKey $searchKey
27
     *
28
     * @throws HeaderNotFoundException
29
     *
30
     * @return Header
31
     */
32
    public function getHeader(HeaderKey $searchKey)
33
    {
34
        foreach ($this as $header) {
35
            if ($searchKey->asString() === $header->getKey()->asString()) {
36
                return $header;
37
            }
38
        }
39
40
        throw new HeaderNotFoundException($searchKey);
41
    }
42
43
    /**
44
     * @param HeaderKey $searchKey
45
     *
46
     * @return bool
47
     */
48
    public function headerKeyExists(HeaderKey $searchKey)
49
    {
50
        try {
51
            return $this->getHeader($searchKey) !== null;
52
        } catch (HeaderNotFoundException $exception) {
53
            return false;
54
        }
55
    }
56
57
    /**
58
     * @param Header $searchHeader
59
     *
60
     * @return bool
61
     */
62
    public function headerExists(Header $searchHeader)
63
    {
64
        try {
65
            $header = $this->getHeader($searchHeader->getKey());
66
67
            return $header->getValue()->asString() === $searchHeader->getValue()->asString();
68
        } catch (HeaderNotFoundException $exception) {
69
            return false;
70
        }
71
    }
72
}
73