Completed
Push — master ( 8619b3...819e89 )
by Thomas
05:42
created

Responses::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 3
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 1
Metric Value
dl 3
loc 3
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
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
11 View Code Duplication
class Responses implements Arrayable {
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
	
13
	use ExtensionPart;
14
	
15
	/** @var Map */
16
	private $responses;
17
	
18 11
	public function __construct($contents = null) {
19 11
		$this->parse($contents === null ? new Map() : $contents);
20 11
	}
21
	
22 11
	private function parse($contents) {
23 11
		$data = CollectionUtils::toMap($contents);
24
25
		// responses
26 11
		$this->responses = new Map();
27 11
		foreach ($data as $r => $response) {
28 5
			if (!Text::create($r)->startsWith('x-')) {
29 5
				$this->responses->set($r, new Response($r, $response));
30 5
			}
31 11
		}
32
		
33
		// extensions
34 11
		$this->parseExtensions($data);
35 11
	}
36
	
37 6
	public function toArray() {
38 6
		$responses = clone $this->responses;
39 6
		$responses->setAll($this->getExtensions());
40 6
		return $responses->toArray();
41
	}
42
43 1
	public function size() {
44 1
		return $this->responses->size();
45
	}
46
47
	/**
48
	 * Returns whether the given response exists
49
	 * 
50
	 * @param string $code
51
	 * @return boolean
52
	 */
53 1
	public function has($code) {
54 1
		return $this->responses->has($code);
55
	}
56
	
57
	/**
58
	 * Returns whether the given response exists
59
	 * 
60
	 * @param Response $response
61
	 * @return boolean
62
	 */
63 1
	public function contains(Response $response) {
64 1
		return $this->responses->contains($response);
65
	}
66
	
67
	/**
68
	 * Returns the reponse info for the given code
69
	 * 
70
	 * @param string $code
71
	 * @return Response
72
	 */
73 2
	public function get($code) {
74 2
		return $this->responses->get($code);
75
	}
76
	
77
	/**
78
	 * Sets the response
79
	 * 
80
	 * @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...
81
	 */
82 1
	public function add(Response $response) {
83 1
		$this->responses->set($response->getCode(), $response);
84 1
	}
85
	
86
	/**
87
	 * Removes the given repsonse
88
	 * 
89
	 * @param string $code
90
	 */
91 1
	public function remove($code) {
92 1
		$this->responses->remove($code);
93 1
	}
94
}
95