Response::parse()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 9
cts 9
cp 1
rs 9.8666
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
namespace gossi\swagger;
3
4
use gossi\swagger\collections\Headers;
5
use gossi\swagger\parts\DescriptionPart;
6
use gossi\swagger\parts\ExtensionPart;
7
use gossi\swagger\parts\RefPart;
8
use gossi\swagger\parts\SchemaPart;
9
use phootwork\collection\CollectionUtils;
10
use phootwork\collection\Map;
11
use phootwork\lang\Arrayable;
12
13
class Response extends AbstractModel implements Arrayable {
14
15
	use RefPart;
16
	use DescriptionPart;
17
	use SchemaPart;
18
	use ExtensionPart;
19
20
	/** @var string */
21
	private $code;
22
23
	/** @var Map */
24
	private $examples;
25
26
	/** @var Headers */
27
	private $headers;
28
29 8
	public function __construct($code, $contents = []) {
30 8
		$this->code = $code;
31 8
		$this->parse($contents);
32 8
	}
33
34 8
	private function parse($contents) {
35 8
		$data = CollectionUtils::toMap($contents);
36
37 8
		$this->examples = $data->get('examples', new Map());
38 8
		$this->headers = new Headers($data->get('headers'));
39
40
		// parts
41 8
		$this->parseRef($data);
42 8
		$this->parseDescription($data);
43 8
		$this->parseSchema($data);
44 8
		$this->parseExtensions($data);
45 8
	}
46
47 8
	public function toArray() {
48 8
		return $this->export('description', 'schema', 'headers', 'examples');
49
	}
50
51
	/**
52
	 * Returns the responses code
53
	 * 
54
	 * @return string
55
	 */
56 1
	public function getCode() {
57 1
		return $this->code;
58
	}
59
60
	/**
61
	 * 
62
	 * @return Map
63
	 */
64
	public function getExamples() {
65
		return $this->examples;
66
	}
67
68
	/**
69
	 * Returns headers for this response
70
	 * 
71
	 * @return Headers
72
	 */
73 1
	public function getHeaders() {
74 1
		return $this->headers;
75
	}
76
77
}
78