Completed
Pull Request — master (#3)
by Guilh
02:22
created

Headers::contains()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace gossi\swagger\collections;
4
5
use gossi\swagger\Header;
6
use phootwork\collection\CollectionUtils;
7
use phootwork\collection\Map;
8
use phootwork\lang\Arrayable;
9
10
class Headers implements Arrayable, \Iterator
11
{
12
    /** @var Map */
13
    private $headers;
14
15 7
    public function __construct($contents = [])
16
    {
17 7
        $this->parse($contents === null ? [] : $contents);
18 7
    }
19
20 7
    private function parse($contents)
21
    {
22 7
        $data = CollectionUtils::toMap($contents);
23
24
        // headers
25 7
        $this->headers = new Map();
26 7
        foreach ($data as $h => $props) {
27 1
            $this->headers->set($h, new Header($h, $props));
28 7
        }
29 7
    }
30
31 6
    public function toArray()
32
    {
33 6
        return $this->headers->toArray();
34
    }
35
36 1
    public function size()
37
    {
38 1
        return $this->headers->size();
39
    }
40
41
    /**
42
     * Returns whether a header with the given name exists.
43
     * 
44
     * @param string $header
45
     *
46
     * @return bool
47
     */
48 1
    public function has($header)
49
    {
50 1
        return $this->headers->has($header);
51
    }
52
53
    /**
54
     * Returns whether the given header exists.
55
     *
56
     * @param Header $header
57
     *
58
     * @return bool
59
     */
60 1
    public function contains(Header $header)
61
    {
62 1
        return $this->headers->contains($header);
63
    }
64
65
    /**
66
     * Returns the header info for the given code.
67
     * 
68
     * @param string $header
69
     *
70
     * @return Header
71
     */
72 1
    public function get($header)
73
    {
74 1
        return $this->headers->get($header);
75
    }
76
77
    /**
78
     * Sets the header.
79
     * 
80
     * @param Header $header
81
     */
82 1
    public function add(Header $header)
83
    {
84 1
        $this->headers->set($header->getHeader(), $header);
85 1
    }
86
87
    /**
88
     * Removes the given header.
89
     * 
90
     * @param string $header
91
     */
92 1
    public function remove($header)
93
    {
94 1
        $this->headers->remove($header);
95 1
    }
96
97
    public function current()
98
    {
99
        return $this->headers->current();
100
    }
101
102
    public function key()
103
    {
104
        return $this->headers->key();
105
    }
106
107
    public function next()
108
    {
109
        return $this->headers->next();
110
    }
111
112
    public function rewind()
113
    {
114
        return $this->headers->rewind();
115
    }
116
117
    public function valid()
118
    {
119
        return $this->headers->valid();
120
    }
121
}
122