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

Parameter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace gossi\swagger;
4
5
use gossi\swagger\parts\DescriptionPart;
6
use gossi\swagger\parts\ExtensionPart;
7
use gossi\swagger\parts\ItemsPart;
8
use gossi\swagger\parts\RequiredPart;
9
use gossi\swagger\parts\TypePart;
10
use phootwork\collection\CollectionUtils;
11
use gossi\swagger\parts\SchemaPart;
12
use gossi\swagger\parts\RefPart;
13
use phootwork\lang\Arrayable;
14
15
class Parameter extends AbstractModel implements Arrayable
16
{
17
    use RefPart;
18
    use DescriptionPart;
19
    use SchemaPart;
20
    use TypePart;
21
    use ItemsPart;
22
    use RequiredPart;
23
    use ExtensionPart;
24
25
    /** @var string */
26
    private $name;
27
28
    /** @var string */
29
    private $in;
30
31
    /** @var bool */
32
    private $allowEmptyValue = false;
33
34 5
    public function __construct($contents = [])
35
    {
36 5
        $this->parse($contents);
37 5
    }
38
39 5
    private function parse($contents = [])
40
    {
41 5
        $data = CollectionUtils::toMap($contents);
42
43 5
        $this->name = $data->get('name');
44 5
        $this->in = $data->get('in');
45 5
        $this->allowEmptyValue = $data->has('allowEmptyValue') && $data->get('allowEmptyValue');
46
47
        // parts
48 5
        $this->parseRef($data);
49 5
        $this->parseDescription($data);
50 5
        $this->parseSchema($data);
51 5
        $this->parseRequired($data);
52 5
        $this->parseType($data);
53 5
        $this->parseItems($data);
54 5
        $this->parseExtensions($data);
55 5
    }
56
57 4
    public function toArray()
58
    {
59 4
        return $this->export('name', 'in', 'allowEmptyValue', 'required', 'description', 'schema',
60 4
                $this->getTypeExportFields(), 'items');
61
    }
62
63
    /**
64
     * @return string
65
     */
66 4
    public function getName()
67
    {
68 1
        return $this->name;
69 4
    }
70
71
    /**
72
     * @param string $name
73
     */
74 1
    public function setName($name)
75
    {
76 1
        $this->name = $name;
77
78 1
        return $this;
79
    }
80
81
    /**
82
     * @return string
83
     */
84
    public function getIn()
85
    {
86
        return $this->in;
87
    }
88
89
    /**
90
     * @param string $in
91
     */
92
    public function setIn($in)
93
    {
94
        $this->in = $in;
95
96
        return $this;
97
    }
98
99
    /**
100
     * @return bool
101
     */
102
    public function getAllowEmptyValue()
103
    {
104
        return $this->allowEmptyValue;
105
    }
106
107
    /**
108
     * Sets the ability to pass empty-valued parameters. This is valid only for either `query` or 
109
     * `formData` parameters and allows you to send a parameter with a name only or an empty value. 
110
     * Default value is `false`.
111
     * 
112
     * @param bool $allowEmptyValue
113
     */
114
    public function setAllowEmptyValue($allowEmptyValue)
115
    {
116
        $this->allowEmptyValue = $allowEmptyValue;
117
118
        return $this;
119
    }
120
}
121