Completed
Push — master ( 10a146...62fa38 )
by Thomas
8s
created

Headers   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 72.21%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 16
c 5
b 0
f 0
lcom 1
cbo 3
dl 0
loc 95
ccs 26
cts 36
cp 0.7221
rs 10

14 Methods

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