Responses::parse()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 10
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3
1
<?php
2
namespace gossi\swagger\collections;
3
4
use gossi\swagger\parts\ExtensionPart;
5
use gossi\swagger\Response;
6
use phootwork\collection\CollectionUtils;
7
use phootwork\collection\Map;
8
use phootwork\lang\Arrayable;
9
use phootwork\lang\Text;
10
use gossi\swagger\AbstractModel;
11
12
class Responses extends AbstractModel implements Arrayable, \Iterator {
13
14
	use ExtensionPart;
15
16
	/** @var Map */
17
	private $responses;
18
19 13
	public function __construct($contents = []) {
20 13
		$this->parse($contents === null ? [] : $contents);
21 13
	}
22
23 13
	private function parse($contents) {
24 13
		$data = CollectionUtils::toMap($contents);
25
26
		// responses
27 13
		$this->responses = new Map();
28 13
		foreach ($data as $r => $response) {
29 7
			if (!Text::create($r)->startsWith('x-')) {
30 7
				$this->responses->set($r, new Response($r, $response));
31 7
			}
32 13
		}
33
34
		// extensions
35 13
		$this->parseExtensions($data);
36 13
	}
37
38 9
	public function toArray() {
39 9
		$responses = clone $this->responses;
40 9
		$responses->setAll($this->getExtensions());
41
42 9
		return CollectionUtils::toArrayRecursive($responses);
43
	}
44
45 1
	public function size() {
46 1
		return $this->responses->size();
47
	}
48
49
	/**
50
	 * Returns whether the given response exists
51
	 *
52
	 * @param string $code
53
	 * @return bool
54
	 */
55 1
	public function has($code) {
56 1
		return $this->responses->has($code);
57
	}
58
59
	/**
60
	 * Returns whether the given response exists
61
	 *
62
	 * @param Response $response
63
	 * @return bool
64
	 */
65 1
	public function contains(Response $response) {
66 1
		return $this->responses->contains($response);
67
	}
68
69
	/**
70
	 * Returns the reponse info for the given code
71
	 *
72
	 * @param string $code
73
	 * @return Response
74
	 */
75 2
	public function get($code) {
76 2
		if (!$this->responses->has($code)) {
77
			$this->responses->set($code, new Response($code));
78
		}
79
80 2
		return $this->responses->get($code);
81
	}
82
83
	/**
84
	 * Sets the response
85
	 *
86
	 * @param Response $code
0 ignored issues
show
Bug introduced by
There is no parameter named $code. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
87
	 */
88 9
	public function add(Response $response) {
89 9
		$this->responses->set($response->getCode(), $response);
90 1
	}
91
92
	/**
93
	 * Adds all responses from another responses collection. Will overwrite existing ones.
94
	 *
95
	 * @param Responses $responses
96
	 */
97
	public function addAll(Responses $responses) {
98
		foreach ($responses as $response) {
99
			$this->add($response);
100
		}
101
	}
102
103
	/**
104
	 * Removes the given repsonse
105
	 *
106
	 * @param string $code
107
	 */
108 1
	public function remove($code) {
109 1
		$this->responses->remove($code);
110 1
	}
111
112
	public function current() {
113
		return $this->responses->current();
114
	}
115
116
	public function key() {
117
		return $this->responses->key();
118
	}
119
120
	public function next() {
121
		return $this->responses->next();
122
	}
123
124
	public function rewind() {
125
		return $this->responses->rewind();
126
	}
127
128
	public function valid() {
129
		return $this->responses->valid();
130
	}
131
}
132