Schema::getAllOf()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
namespace gossi\swagger;
3
4
use gossi\swagger\collections\Definitions;
5
use gossi\swagger\parts\DescriptionPart;
6
use gossi\swagger\parts\ExtensionPart;
7
use gossi\swagger\parts\ExternalDocsPart;
8
use gossi\swagger\parts\ItemsPart;
9
use gossi\swagger\parts\RefPart;
10
use gossi\swagger\parts\TypePart;
11
use phootwork\collection\ArrayList;
12
use phootwork\collection\CollectionUtils;
13
use phootwork\collection\Map;
14
use phootwork\lang\Arrayable;
15
16
class Schema extends AbstractModel implements Arrayable {
17
18
	use RefPart;
19
	use TypePart;
20
	use DescriptionPart;
21
	use ItemsPart;
22
	use ExternalDocsPart;
23
	use ExtensionPart;
24
25
	/** @var string */
26
	private $discriminator;
27
28
	/** @var bool */
29
	private $readOnly = false;
30
31
	/** @var string */
32
	private $title;
33
34
	private $xml;
35
36
	/** @var string */
37
	private $example;
38
39
	/** @var ArrayList|bool */
40
	private $required;
41
42
	/** @var Definitions */
43
	private $properties;
44
45
	/** @var ArrayList */
46
	private $allOf;
47
48
	/** @var Schema */
49
	private $additionalProperties;
50
51 10
	public function __construct($contents = null) {
52 10
		$this->parse($contents === null ? new Map() : $contents);
53 10
	}
54
55 10
	private function parse($contents = []) {
56 10
		$data = CollectionUtils::toMap($contents);
57
58 10
		$this->title = $data->get('title');
59 10
		$this->discriminator = $data->get('discriminator');
60 10
		$this->readOnly = $data->has('readOnly') && $data->get('readOnly');
61 10
		$this->example = $data->get('example');
62 10
		$this->required = $data->get('required');
63 10
		$this->properties = new Definitions($data->get('properties'));
64 10
		if ($data->has('additionalProperties')) {
65
			$this->additionalProperties = new self($data->get('additionalProperties'));
66
		}
67
68 10
		$this->allOf = new ArrayList();
69 10
		if ($data->has('allOf')) {
70 3
			foreach ($data->get('allOf') as $schema) {
71 3
				$this->allOf->add(new self($schema));
72 3
			}
73 3
		}
74
75
		// parts
76 10
		$this->parseRef($data);
77 10
		$this->parseType($data);
78 10
		$this->parseDescription($data);
79 10
		$this->parseItems($data);
80 10
		$this->parseExternalDocs($data);
81 10
		$this->parseExtensions($data);
82 10
	}
83
84 10
	public function toArray() {
85 10
		return $this->export('title', 'discriminator', 'description', 'readOnly', 'example',
86 10
				'externalDocs', $this->getTypeExportFields(), 'items', 'required',
87 10
				'properties', 'additionalProperties', 'allOf');
88
	}
89
90
	/**
91
	 *
92
	 * @return bool|array
93
	 */
94
	public function getRequired() {
95
		return $this->required;
96
	}
97
98
	/**
99
	 *
100
	 * @param bool|array $required
101
	 * @return $this
102
	 */
103
	public function setRequired($required) {
104
		$this->required = $required;
0 ignored issues
show
Documentation Bug introduced by
It seems like $required can also be of type array. However, the property $required is declared as type object<phootwork\collection\ArrayList>|boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
105
		return $this;
106
	}
107
108
	/**
109
	 *
110
	 * @return string
111
	 */
112
	public function getDiscriminator() {
113
		return $this->discriminator;
114
	}
115
116
	/**
117
	 *
118
	 * @param string $discriminator
119
	 */
120
	public function setDiscriminator($discriminator) {
121
		$this->discriminator = $discriminator;
122
		return $this;
123
	}
124
125
	/**
126
	 *
127
	 * @return bool
128
	 */
129
	public function isReadOnly() {
130
		return $this->readOnly;
131
	}
132
133
	/**
134
	 *
135
	 * @param bool $readOnly
136
	 */
137
	public function setReadOnly($readOnly) {
138
		$this->readOnly = $readOnly;
139
		return $this;
140
	}
141
142
	/**
143
	 *
144
	 * @return string
145
	 */
146
	public function getExample() {
147
		return $this->example;
148
	}
149
150
	/**
151
	 *
152
	 * @param string $example
153
	 */
154
	public function setExample($example) {
155
		$this->example = $example;
156
		return $this;
157
	}
158
159
	/**
160
	 *
161
	 * @return string
162
	 */
163
	public function getTitle() {
164
		return $this->title;
165
	}
166
167
	/**
168
	 *
169
	 * @param string $title
170
	 * @return $this
171
	 */
172
	public function setTitle($title) {
173
		$this->title = $title;
174
		return $this;
175
	}
176
177
	/**
178
	 *
179
	 * @return Definitions
180
	 */
181
	public function getProperties() {
182
		return $this->properties;
183
	}
184
185
	/**
186
	 *
187
	 * @return ArrayList
188
	 */
189
	public function getAllOf() {
190
		return $this->allOf;
191
	}
192
193
	/**
194
	 *
195
	 * @return Schema
196
	 */
197
	public function getAdditionalProperties() {
198
		if ($this->additionalProperties === null) {
199
			$this->additionalProperties = new self();
200
		}
201
		return $this->additionalProperties;
202
	}
203
204
}
205