Completed
Push — master ( 8f1f27...a615f9 )
by Viacheslav
03:25 queued 22s
created

JsonSchema::setMinLength()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
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;
8
9
use Swaggest\JsonSchema\Constraint\Properties;
10
use Swaggest\JsonSchema\Schema as JsonBasicSchema;
11
use Swaggest\JsonSchema\Structure\ClassStructure;
12
13
14
class JsonSchema extends ClassStructure {
15
	/** @var string */
16
	public $id;
17
18
	/** @var string */
19
	public $schema;
20
21
	/** @var string */
22
	public $title;
23
24
	/** @var string */
25
	public $description;
26
27
	public $default;
28
29
	/** @var float */
30
	public $multipleOf;
31
32
	/** @var float */
33
	public $maximum;
34
35
	/** @var bool */
36
	public $exclusiveMaximum;
37
38
	/** @var float */
39
	public $minimum;
40
41
	/** @var bool */
42
	public $exclusiveMinimum;
43
44
	/** @var int */
45
	public $maxLength;
46
47
	/** @var int */
48
	public $minLength;
49
50
	/** @var string */
51
	public $pattern;
52
53
	/** @var bool|JsonSchema */
54
	public $additionalItems;
55
56
	/** @var JsonSchema|JsonSchema[]|array */
57
	public $items;
58
59
	/** @var int */
60
	public $maxItems;
61
62
	/** @var int */
63
	public $minItems;
64
65
	/** @var bool */
66
	public $uniqueItems;
67
68
	/** @var int */
69
	public $maxProperties;
70
71
	/** @var int */
72
	public $minProperties;
73
74
	/** @var string[]|array */
75
	public $required;
76
77
	/** @var bool|JsonSchema */
78
	public $additionalProperties;
79
80
	/** @var JsonSchema[] */
81
	public $definitions;
82
83
	/** @var JsonSchema[] */
84
	public $properties;
85
86
	/** @var JsonSchema[] */
87
	public $patternProperties;
88
89
	/** @var JsonSchema[]|string[][]|array[] */
90
	public $dependencies;
91
92
	/** @var array */
93
	public $enum;
94
95
	/** @var array */
96
	public $type;
97
98
	/** @var string */
99
	public $format;
100
101
	/** @var string */
102
	public $ref;
103
104
	/** @var JsonSchema[]|array */
105
	public $allOf;
106
107
	/** @var JsonSchema[]|array */
108
	public $anyOf;
109
110
	/** @var JsonSchema[]|array */
111
	public $oneOf;
112
113
	/** @var JsonSchema Core schema meta-schema */
114
	public $not;
115
116
	/**
117
	 * @param Properties|static $properties
118
	 * @param JsonBasicSchema $ownerSchema
119
	 */
120
	public static function setUpProperties($properties, JsonBasicSchema $ownerSchema)
121
	{
122
		$properties->id = JsonBasicSchema::string();
123
		$properties->id->format = 'uri';
124
		$properties->schema = JsonBasicSchema::string();
125
		$properties->schema->format = 'uri';
126
		$ownerSchema->addPropertyMapping('$schema', self::names()->schema);
0 ignored issues
show
Documentation introduced by
The property schema does not exist on object<Swaggest\JsonSchema\NameMirror>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
127
		$properties->title = JsonBasicSchema::string();
128
		$properties->description = JsonBasicSchema::string();
129
		$properties->default = new JsonBasicSchema();
130
		$properties->multipleOf = JsonBasicSchema::number();
131
		$properties->multipleOf->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...
132
		$properties->multipleOf->exclusiveMinimum = true;
133
		$properties->maximum = JsonBasicSchema::number();
134
		$properties->exclusiveMaximum = JsonBasicSchema::boolean();
135
		$properties->exclusiveMaximum->default = false;
136
		$properties->minimum = JsonBasicSchema::number();
137
		$properties->exclusiveMinimum = JsonBasicSchema::boolean();
138
		$properties->exclusiveMinimum->default = false;
139
		$properties->maxLength = JsonBasicSchema::integer();
140
		$properties->maxLength->minimum = 0;
141
		$properties->minLength = new JsonBasicSchema();
142
		$properties->minLength->allOf[0] = JsonBasicSchema::integer();
143
		$properties->minLength->allOf[0]->minimum = 0;
144
		$properties->minLength->allOf[1] = new JsonBasicSchema();
145
		$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...
146
		$properties->pattern = JsonBasicSchema::string();
147
		$properties->pattern->format = 'regex';
148
		$properties->additionalItems = new JsonBasicSchema();
149
		$properties->additionalItems->anyOf[0] = JsonBasicSchema::boolean();
150
		$properties->additionalItems->anyOf[1] = JsonBasicSchema::schema();
151
		$properties->additionalItems->default = (object)array (
152
		);
153
		$properties->items = new JsonBasicSchema();
154
		$properties->items->anyOf[0] = JsonBasicSchema::schema();
155
		$properties->items->anyOf[1] = JsonBasicSchema::arr();
156
		$properties->items->anyOf[1]->items = JsonBasicSchema::schema();
157
		$properties->items->anyOf[1]->minItems = 1;
158
		$properties->items->default = (object)array (
159
		);
160
		$properties->maxItems = JsonBasicSchema::integer();
161
		$properties->maxItems->minimum = 0;
162
		$properties->minItems = new JsonBasicSchema();
163
		$properties->minItems->allOf[0] = JsonBasicSchema::integer();
164
		$properties->minItems->allOf[0]->minimum = 0;
165
		$properties->minItems->allOf[1] = new JsonBasicSchema();
166
		$properties->minItems->allOf[1]->default = 0;
167
		$properties->uniqueItems = JsonBasicSchema::boolean();
168
		$properties->uniqueItems->default = false;
169
		$properties->maxProperties = JsonBasicSchema::integer();
170
		$properties->maxProperties->minimum = 0;
171
		$properties->minProperties = new JsonBasicSchema();
172
		$properties->minProperties->allOf[0] = JsonBasicSchema::integer();
173
		$properties->minProperties->allOf[0]->minimum = 0;
174
		$properties->minProperties->allOf[1] = new JsonBasicSchema();
175
		$properties->minProperties->allOf[1]->default = 0;
176
		$properties->required = JsonBasicSchema::arr();
177
		$properties->required->items = JsonBasicSchema::string();
178
		$properties->required->minItems = 1;
179
		$properties->required->uniqueItems = true;
180
		$properties->additionalProperties = new JsonBasicSchema();
181
		$properties->additionalProperties->anyOf[0] = JsonBasicSchema::boolean();
182
		$properties->additionalProperties->anyOf[1] = JsonBasicSchema::schema();
183
		$properties->additionalProperties->default = (object)array (
184
		);
185
		$properties->definitions = JsonBasicSchema::object();
186
		$properties->definitions->additionalProperties = JsonBasicSchema::schema();
187
		$properties->definitions->default = (object)array (
188
		);
189
		$properties->properties = JsonBasicSchema::object();
190
		$properties->properties->additionalProperties = JsonBasicSchema::schema();
191
		$properties->properties->default = (object)array (
192
		);
193
		$properties->patternProperties = JsonBasicSchema::object();
194
		$properties->patternProperties->additionalProperties = JsonBasicSchema::schema();
195
		$properties->patternProperties->default = (object)array (
196
		);
197
		$properties->dependencies = JsonBasicSchema::object();
198
		$properties->dependencies->additionalProperties = new JsonBasicSchema();
199
		$properties->dependencies->additionalProperties->anyOf[0] = JsonBasicSchema::schema();
200
		$properties->dependencies->additionalProperties->anyOf[1] = JsonBasicSchema::arr();
201
		$properties->dependencies->additionalProperties->anyOf[1]->items = JsonBasicSchema::string();
202
		$properties->dependencies->additionalProperties->anyOf[1]->minItems = 1;
203
		$properties->dependencies->additionalProperties->anyOf[1]->uniqueItems = true;
204
		$properties->enum = JsonBasicSchema::arr();
205
		$properties->enum->minItems = 1;
206
		$properties->enum->uniqueItems = true;
207
		$properties->type = new JsonBasicSchema();
208
		$properties->type->anyOf[0] = new JsonBasicSchema();
209
		$properties->type->anyOf[0]->enum = array (
210
		  0 => 'array',
211
		  1 => 'boolean',
212
		  2 => 'integer',
213
		  3 => 'null',
214
		  4 => 'number',
215
		  5 => 'object',
216
		  6 => 'string',
217
		);
218
		$properties->type->anyOf[1] = JsonBasicSchema::arr();
219
		$properties->type->anyOf[1]->items = new JsonBasicSchema();
220
		$properties->type->anyOf[1]->items->enum = array (
221
		  0 => 'array',
222
		  1 => 'boolean',
223
		  2 => 'integer',
224
		  3 => 'null',
225
		  4 => 'number',
226
		  5 => 'object',
227
		  6 => 'string',
228
		);
229
		$properties->type->anyOf[1]->minItems = 1;
230
		$properties->type->anyOf[1]->uniqueItems = true;
231
		$properties->format = JsonBasicSchema::string();
232
		$properties->ref = JsonBasicSchema::string();
233
		$ownerSchema->addPropertyMapping('$ref', self::names()->ref);
0 ignored issues
show
Documentation introduced by
The property ref does not exist on object<Swaggest\JsonSchema\NameMirror>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
234
		$properties->allOf = JsonBasicSchema::arr();
235
		$properties->allOf->items = JsonBasicSchema::schema();
236
		$properties->allOf->minItems = 1;
237
		$properties->anyOf = JsonBasicSchema::arr();
238
		$properties->anyOf->items = JsonBasicSchema::schema();
239
		$properties->anyOf->minItems = 1;
240
		$properties->oneOf = JsonBasicSchema::arr();
241
		$properties->oneOf->items = JsonBasicSchema::schema();
242
		$properties->oneOf->minItems = 1;
243
		$properties->not = JsonBasicSchema::schema();
244
		$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...
245
		$ownerSchema->id = 'http://json-schema.org/draft-04/schema#';
246
		$ownerSchema->schema = 'http://json-schema.org/draft-04/schema#';
247
		$ownerSchema->description = 'Core schema meta-schema';
248
		$ownerSchema->default = (object)array (
249
		);
250
		$ownerSchema->dependencies = (object)array (
251
		  'exclusiveMaximum' => 
252
		  array (
253
		    0 => 'maximum',
254
		  ),
255
		  'exclusiveMinimum' => 
256
		  array (
257
		    0 => 'minimum',
258
		  ),
259
		);
260
	}
261
262
	/**
263
	 * @param string $id
264
	 * @return $this
265
	 */
266
	public function setId($id)
267
	{
268
		$this->id = $id;
269
		return $this;
270
	}
271
272
	/**
273
	 * @param string $schema
274
	 * @return $this
275
	 */
276
	public function setSchema($schema)
277
	{
278
		$this->schema = $schema;
279
		return $this;
280
	}
281
282
	/**
283
	 * @param string $title
284
	 * @return $this
285
	 */
286
	public function setTitle($title)
287
	{
288
		$this->title = $title;
289
		return $this;
290
	}
291
292
	/**
293
	 * @param string $description
294
	 * @return $this
295
	 */
296
	public function setDescription($description)
297
	{
298
		$this->description = $description;
299
		return $this;
300
	}
301
302
	/**
303
	 * @param $default
304
	 * @return $this
305
	 */
306
	public function setDefault($default)
307
	{
308
		$this->default = $default;
309
		return $this;
310
	}
311
312
	/**
313
	 * @param float $multipleOf
314
	 * @return $this
315
	 */
316
	public function setMultipleOf($multipleOf)
317
	{
318
		$this->multipleOf = $multipleOf;
319
		return $this;
320
	}
321
322
	/**
323
	 * @param float $maximum
324
	 * @return $this
325
	 */
326
	public function setMaximum($maximum)
327
	{
328
		$this->maximum = $maximum;
329
		return $this;
330
	}
331
332
	/**
333
	 * @param bool $exclusiveMaximum
334
	 * @return $this
335
	 */
336
	public function setExclusiveMaximum($exclusiveMaximum)
337
	{
338
		$this->exclusiveMaximum = $exclusiveMaximum;
339
		return $this;
340
	}
341
342
	/**
343
	 * @param float $minimum
344
	 * @return $this
345
	 */
346
	public function setMinimum($minimum)
347
	{
348
		$this->minimum = $minimum;
349
		return $this;
350
	}
351
352
	/**
353
	 * @param bool $exclusiveMinimum
354
	 * @return $this
355
	 */
356
	public function setExclusiveMinimum($exclusiveMinimum)
357
	{
358
		$this->exclusiveMinimum = $exclusiveMinimum;
359
		return $this;
360
	}
361
362
	/**
363
	 * @param int $maxLength
364
	 * @return $this
365
	 */
366
	public function setMaxLength($maxLength)
367
	{
368
		$this->maxLength = $maxLength;
369
		return $this;
370
	}
371
372
	/**
373
	 * @param int $minLength
374
	 * @return $this
375
	 */
376
	public function setMinLength($minLength)
377
	{
378
		$this->minLength = $minLength;
379
		return $this;
380
	}
381
382
	/**
383
	 * @param string $pattern
384
	 * @return $this
385
	 */
386
	public function setPattern($pattern)
387
	{
388
		$this->pattern = $pattern;
389
		return $this;
390
	}
391
392
	/**
393
	 * @param bool|JsonSchema $additionalItems
394
	 * @return $this
395
	 */
396
	public function setAdditionalItems($additionalItems)
397
	{
398
		$this->additionalItems = $additionalItems;
399
		return $this;
400
	}
401
402
	/**
403
	 * @param JsonSchema|JsonSchema[]|array $items
404
	 * @return $this
405
	 */
406
	public function setItems($items)
407
	{
408
		$this->items = $items;
409
		return $this;
410
	}
411
412
	/**
413
	 * @param int $maxItems
414
	 * @return $this
415
	 */
416
	public function setMaxItems($maxItems)
417
	{
418
		$this->maxItems = $maxItems;
419
		return $this;
420
	}
421
422
	/**
423
	 * @param int $minItems
424
	 * @return $this
425
	 */
426
	public function setMinItems($minItems)
427
	{
428
		$this->minItems = $minItems;
429
		return $this;
430
	}
431
432
	/**
433
	 * @param bool $uniqueItems
434
	 * @return $this
435
	 */
436
	public function setUniqueItems($uniqueItems)
437
	{
438
		$this->uniqueItems = $uniqueItems;
439
		return $this;
440
	}
441
442
	/**
443
	 * @param int $maxProperties
444
	 * @return $this
445
	 */
446
	public function setMaxProperties($maxProperties)
447
	{
448
		$this->maxProperties = $maxProperties;
449
		return $this;
450
	}
451
452
	/**
453
	 * @param int $minProperties
454
	 * @return $this
455
	 */
456
	public function setMinProperties($minProperties)
457
	{
458
		$this->minProperties = $minProperties;
459
		return $this;
460
	}
461
462
	/**
463
	 * @param string[]|array $required
464
	 * @return $this
465
	 */
466
	public function setRequired($required)
467
	{
468
		$this->required = $required;
469
		return $this;
470
	}
471
472
	/**
473
	 * @param bool|JsonSchema $additionalProperties
474
	 * @return $this
475
	 */
476
	public function setAdditionalProperties($additionalProperties)
477
	{
478
		$this->additionalProperties = $additionalProperties;
479
		return $this;
480
	}
481
482
	/**
483
	 * @param JsonSchema[] $definitions
484
	 * @return $this
485
	 */
486
	public function setDefinitions($definitions)
487
	{
488
		$this->definitions = $definitions;
489
		return $this;
490
	}
491
492
	/**
493
	 * @param JsonSchema[] $properties
494
	 * @return $this
495
	 */
496
	public function setProperties($properties)
497
	{
498
		$this->properties = $properties;
499
		return $this;
500
	}
501
502
	/**
503
	 * @param JsonSchema[] $patternProperties
504
	 * @return $this
505
	 */
506
	public function setPatternProperties($patternProperties)
507
	{
508
		$this->patternProperties = $patternProperties;
509
		return $this;
510
	}
511
512
	/**
513
	 * @param JsonSchema[]|string[][]|array[] $dependencies
514
	 * @return $this
515
	 */
516
	public function setDependencies($dependencies)
517
	{
518
		$this->dependencies = $dependencies;
519
		return $this;
520
	}
521
522
	/**
523
	 * @param array $enum
524
	 * @return $this
525
	 */
526
	public function setEnum($enum)
527
	{
528
		$this->enum = $enum;
529
		return $this;
530
	}
531
532
	/**
533
	 * @param array $type
534
	 * @return $this
535
	 */
536
	public function setType($type)
537
	{
538
		$this->type = $type;
539
		return $this;
540
	}
541
542
	/**
543
	 * @param string $format
544
	 * @return $this
545
	 */
546
	public function setFormat($format)
547
	{
548
		$this->format = $format;
549
		return $this;
550
	}
551
552
	/**
553
	 * @param string $ref
554
	 * @return $this
555
	 */
556
	public function setRef($ref)
557
	{
558
		$this->ref = $ref;
559
		return $this;
560
	}
561
562
	/**
563
	 * @param JsonSchema[]|array $allOf
564
	 * @return $this
565
	 */
566
	public function setAllOf($allOf)
567
	{
568
		$this->allOf = $allOf;
569
		return $this;
570
	}
571
572
	/**
573
	 * @param JsonSchema[]|array $anyOf
574
	 * @return $this
575
	 */
576
	public function setAnyOf($anyOf)
577
	{
578
		$this->anyOf = $anyOf;
579
		return $this;
580
	}
581
582
	/**
583
	 * @param JsonSchema[]|array $oneOf
584
	 * @return $this
585
	 */
586
	public function setOneOf($oneOf)
587
	{
588
		$this->oneOf = $oneOf;
589
		return $this;
590
	}
591
592
	/**
593
	 * @param JsonSchema $not Core schema meta-schema
594
	 * @return $this
595
	 */
596
	public function setNot($not)
597
	{
598
		$this->not = $not;
599
		return $this;
600
	}
601
}
602
603