Completed
Pull Request — master (#11)
by Viacheslav
02:53
created

Header::setMaxLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
/**
3
 * @file ATTENTION!!! The code below was carefully crafted by a mean machine.
4
 * Please consider to NOT put any emotional human-generated modifications as the splendid AI will throw them away with no mercy.
5
 */
6
7
namespace Swaggest\JsonSchema\SwaggerSchema;
8
9
use Swaggest\JsonSchema\Constraint\Properties;
10
use Swaggest\JsonSchema\Schema as JsonBasicSchema;
11
use Swaggest\JsonSchema\Structure\ClassStructure;
12
13
14
class Header extends ClassStructure {
15
	/** @var string */
16
	public $type;
17
18
	/** @var string */
19
	public $format;
20
21
	/** @var PrimitivesItems */
22
	public $items;
23
24
	/** @var string */
25
	public $collectionFormat;
26
27
	public $default;
28
29
	/** @var float */
30
	public $maximum;
31
32
	/** @var bool */
33
	public $exclusiveMaximum;
34
35
	/** @var float */
36
	public $minimum;
37
38
	/** @var bool */
39
	public $exclusiveMinimum;
40
41
	/** @var int */
42
	public $maxLength;
43
44
	/** @var int */
45
	public $minLength;
46
47
	/** @var string */
48
	public $pattern;
49
50
	/** @var int */
51
	public $maxItems;
52
53
	/** @var int */
54
	public $minItems;
55
56
	/** @var bool */
57
	public $uniqueItems;
58
59
	/** @var array */
60
	public $enum;
61
62
	/** @var float */
63
	public $multipleOf;
64
65
	/** @var string */
66
	public $description;
67
68
	/**
69
	 * @param Properties|static $properties
70
	 * @param JsonBasicSchema $ownerSchema
71
	 */
72
	public static function setUpProperties($properties, JsonBasicSchema $ownerSchema)
73
	{
74
		$properties->type = JsonBasicSchema::string();
75
		$properties->type->enum = array (
76
		  0 => 'string',
77
		  1 => 'number',
78
		  2 => 'integer',
79
		  3 => 'boolean',
80
		  4 => 'array',
81
		);
82
		$properties->format = JsonBasicSchema::string();
83
		$properties->items = PrimitivesItems::schema();
84
		$properties->collectionFormat = JsonBasicSchema::string();
85
		$properties->collectionFormat->default = 'csv';
86
		$properties->collectionFormat->enum = array (
87
		  0 => 'csv',
88
		  1 => 'ssv',
89
		  2 => 'tsv',
90
		  3 => 'pipes',
91
		);
92
		$properties->default = new JsonBasicSchema();
93
		$properties->maximum = JsonBasicSchema::number();
94
		$properties->exclusiveMaximum = JsonBasicSchema::boolean();
95
		$properties->exclusiveMaximum->default = false;
96
		$properties->minimum = JsonBasicSchema::number();
97
		$properties->exclusiveMinimum = JsonBasicSchema::boolean();
98
		$properties->exclusiveMinimum->default = false;
99
		$properties->maxLength = JsonBasicSchema::integer();
100
		$properties->maxLength->minimum = 0;
0 ignored issues
show
Documentation Bug introduced by
The property $minimum was declared of type double, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
101
		$properties->minLength = new JsonBasicSchema();
102
		$properties->minLength->allOf[0] = JsonBasicSchema::integer();
103
		$properties->minLength->allOf[0]->minimum = 0;
104
		$properties->minLength->allOf[1] = new JsonBasicSchema();
105
		$properties->minLength->allOf[1]->default = 0;
0 ignored issues
show
Documentation Bug introduced by
It seems like 0 of type integer is incompatible with the declared type false|string of property $default.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
106
		$properties->pattern = JsonBasicSchema::string();
107
		$properties->pattern->format = 'regex';
108
		$properties->maxItems = JsonBasicSchema::integer();
109
		$properties->maxItems->minimum = 0;
110
		$properties->minItems = new JsonBasicSchema();
111
		$properties->minItems->allOf[0] = JsonBasicSchema::integer();
112
		$properties->minItems->allOf[0]->minimum = 0;
113
		$properties->minItems->allOf[1] = new JsonBasicSchema();
114
		$properties->minItems->allOf[1]->default = 0;
115
		$properties->uniqueItems = JsonBasicSchema::boolean();
116
		$properties->uniqueItems->default = false;
117
		$properties->enum = JsonBasicSchema::arr();
118
		$properties->enum->minItems = 1;
119
		$properties->enum->uniqueItems = true;
120
		$properties->multipleOf = JsonBasicSchema::number();
121
		$properties->multipleOf->minimum = 0;
122
		$properties->multipleOf->exclusiveMinimum = true;
123
		$properties->description = JsonBasicSchema::string();
124
		$ownerSchema->type = 'object';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'object' of type string is incompatible with the declared type array of property $type.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
125
		$ownerSchema->additionalProperties = false;
126
		$ownerSchema->patternProperties['^x-'] = new JsonBasicSchema();
127
		$ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.';
128
		$ownerSchema->required = array (
129
		  0 => 'type',
130
		);
131
	}
132
133
	/**
134
	 * @param string $type
135
	 * @return $this
136
	 */
137
	public function setType($type)
138
	{
139
		$this->type = $type;
140
		return $this;
141
	}
142
143
	/**
144
	 * @param string $format
145
	 * @return $this
146
	 */
147
	public function setFormat($format)
148
	{
149
		$this->format = $format;
150
		return $this;
151
	}
152
153
	/**
154
	 * @param PrimitivesItems $items
155
	 * @return $this
156
	 */
157
	public function setItems($items)
158
	{
159
		$this->items = $items;
160
		return $this;
161
	}
162
163
	/**
164
	 * @param string $collectionFormat
165
	 * @return $this
166
	 */
167
	public function setCollectionFormat($collectionFormat)
168
	{
169
		$this->collectionFormat = $collectionFormat;
170
		return $this;
171
	}
172
173
	/**
174
	 * @param $default
175
	 * @return $this
176
	 */
177
	public function setDefault($default)
178
	{
179
		$this->default = $default;
180
		return $this;
181
	}
182
183
	/**
184
	 * @param float $maximum
185
	 * @return $this
186
	 */
187
	public function setMaximum($maximum)
188
	{
189
		$this->maximum = $maximum;
190
		return $this;
191
	}
192
193
	/**
194
	 * @param bool $exclusiveMaximum
195
	 * @return $this
196
	 */
197
	public function setExclusiveMaximum($exclusiveMaximum)
198
	{
199
		$this->exclusiveMaximum = $exclusiveMaximum;
200
		return $this;
201
	}
202
203
	/**
204
	 * @param float $minimum
205
	 * @return $this
206
	 */
207
	public function setMinimum($minimum)
208
	{
209
		$this->minimum = $minimum;
210
		return $this;
211
	}
212
213
	/**
214
	 * @param bool $exclusiveMinimum
215
	 * @return $this
216
	 */
217
	public function setExclusiveMinimum($exclusiveMinimum)
218
	{
219
		$this->exclusiveMinimum = $exclusiveMinimum;
220
		return $this;
221
	}
222
223
	/**
224
	 * @param int $maxLength
225
	 * @return $this
226
	 */
227
	public function setMaxLength($maxLength)
228
	{
229
		$this->maxLength = $maxLength;
230
		return $this;
231
	}
232
233
	/**
234
	 * @param int $minLength
235
	 * @return $this
236
	 */
237
	public function setMinLength($minLength)
238
	{
239
		$this->minLength = $minLength;
240
		return $this;
241
	}
242
243
	/**
244
	 * @param string $pattern
245
	 * @return $this
246
	 */
247
	public function setPattern($pattern)
248
	{
249
		$this->pattern = $pattern;
250
		return $this;
251
	}
252
253
	/**
254
	 * @param int $maxItems
255
	 * @return $this
256
	 */
257
	public function setMaxItems($maxItems)
258
	{
259
		$this->maxItems = $maxItems;
260
		return $this;
261
	}
262
263
	/**
264
	 * @param int $minItems
265
	 * @return $this
266
	 */
267
	public function setMinItems($minItems)
268
	{
269
		$this->minItems = $minItems;
270
		return $this;
271
	}
272
273
	/**
274
	 * @param bool $uniqueItems
275
	 * @return $this
276
	 */
277
	public function setUniqueItems($uniqueItems)
278
	{
279
		$this->uniqueItems = $uniqueItems;
280
		return $this;
281
	}
282
283
	/**
284
	 * @param array $enum
285
	 * @return $this
286
	 */
287
	public function setEnum($enum)
288
	{
289
		$this->enum = $enum;
290
		return $this;
291
	}
292
293
	/**
294
	 * @param float $multipleOf
295
	 * @return $this
296
	 */
297
	public function setMultipleOf($multipleOf)
298
	{
299
		$this->multipleOf = $multipleOf;
300
		return $this;
301
	}
302
303
	/**
304
	 * @param string $description
305
	 * @return $this
306
	 */
307
	public function setDescription($description)
308
	{
309
		$this->description = $description;
310
		return $this;
311
	}
312
}
313
314