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

Response   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 69
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Test Coverage

Coverage 95.45%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 6
c 4
b 1
f 0
lcom 1
cbo 8
dl 0
loc 69
ccs 21
cts 22
cp 0.9545
rs 10

6 Methods

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