Completed
Pull Request — master (#9)
by Viacheslav
39:48
created

Schema::setUpProperties()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 101
Code Lines 97

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 101
rs 8.2857
c 0
b 0
f 0
cc 1
eloc 97
nc 1
nop 2

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 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 Schema1;
11
use Swaggest\JsonSchema\Structure\ClassStructure;
12
13
14
class Schema extends ClassStructure {
15
	/** @var string */
16
	public $ref;
17
18
	/** @var string */
19
	public $format;
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 int */
54
	public $maxItems;
55
56
	/** @var int */
57
	public $minItems;
58
59
	/** @var bool */
60
	public $uniqueItems;
61
62
	/** @var int */
63
	public $maxProperties;
64
65
	/** @var int */
66
	public $minProperties;
67
68
	/** @var string[]|array */
69
	public $required;
70
71
	/** @var array */
72
	public $enum;
73
74
	/** @var Schema|bool */
75
	public $additionalProperties;
76
77
	/** @var array */
78
	public $type;
79
80
	/** @var Schema|Schema[]|array */
81
	public $items;
82
83
	/** @var Schema[]|array */
84
	public $allOf;
85
86
	/** @var Schema[] */
87
	public $properties;
88
89
	/** @var string */
90
	public $discriminator;
91
92
	/** @var bool */
93
	public $readOnly;
94
95
	/** @var Xml */
96
	public $xml;
97
98
	/** @var ExternalDocs information about external documentation */
99
	public $externalDocs;
100
101
	public $example;
102
103
	/**
104
	 * @param Properties|static $properties
105
	 * @param Schema1 $ownerSchema
106
	 */
107
	public static function setUpProperties($properties, Schema1 $ownerSchema)
108
	{
109
		$properties->ref = Schema1::string();
110
		$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...
111
		$properties->format = Schema1::string();
112
		$properties->title = Schema1::string();
113
		$properties->description = Schema1::string();
114
		$properties->default = new Schema1();
115
		$properties->multipleOf = Schema1::number();
116
		$properties->multipleOf->minimum = 0;
117
		$properties->multipleOf->exclusiveMinimum = true;
118
		$properties->maximum = Schema1::number();
119
		$properties->exclusiveMaximum = Schema1::boolean();
120
		$properties->exclusiveMaximum->default = false;
0 ignored issues
show
Documentation introduced by
The property default does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
121
		$properties->minimum = Schema1::number();
122
		$properties->exclusiveMinimum = Schema1::boolean();
123
		$properties->exclusiveMinimum->default = false;
0 ignored issues
show
Documentation introduced by
The property default does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
124
		$properties->maxLength = Schema1::integer();
125
		$properties->maxLength->minimum = 0;
126
		$properties->minLength = new Schema1();
127
		$properties->minLength->allOf[0] = Schema1::integer();
128
		$properties->minLength->allOf[0]->minimum = 0;
129
		$properties->minLength->allOf[1] = new Schema1();
130
		$properties->minLength->allOf[1]->default = 0;
0 ignored issues
show
Documentation introduced by
The property default does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
131
		$properties->pattern = Schema1::string();
132
		$properties->pattern->format = 'regex';
133
		$properties->maxItems = Schema1::integer();
134
		$properties->maxItems->minimum = 0;
135
		$properties->minItems = new Schema1();
136
		$properties->minItems->allOf[0] = Schema1::integer();
137
		$properties->minItems->allOf[0]->minimum = 0;
138
		$properties->minItems->allOf[1] = new Schema1();
139
		$properties->minItems->allOf[1]->default = 0;
0 ignored issues
show
Documentation introduced by
The property default does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
140
		$properties->uniqueItems = Schema1::boolean();
141
		$properties->uniqueItems->default = false;
0 ignored issues
show
Documentation introduced by
The property default does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
142
		$properties->maxProperties = Schema1::integer();
143
		$properties->maxProperties->minimum = 0;
144
		$properties->minProperties = new Schema1();
145
		$properties->minProperties->allOf[0] = Schema1::integer();
146
		$properties->minProperties->allOf[0]->minimum = 0;
147
		$properties->minProperties->allOf[1] = new Schema1();
148
		$properties->minProperties->allOf[1]->default = 0;
0 ignored issues
show
Documentation introduced by
The property default does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
149
		$properties->required = Schema1::arr();
150
		$properties->required->items = Schema1::string();
151
		$properties->required->minItems = 1;
152
		$properties->required->uniqueItems = true;
153
		$properties->enum = Schema1::arr();
154
		$properties->enum->minItems = 1;
155
		$properties->enum->uniqueItems = true;
156
		$properties->additionalProperties = new Schema1();
157
		$properties->additionalProperties->anyOf[0] = Schema::schema();
158
		$properties->additionalProperties->anyOf[1] = Schema1::boolean();
159
		$properties->additionalProperties->default = new \stdClass();
0 ignored issues
show
Documentation introduced by
The property default does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
160
		$properties->type = new Schema1();
161
		$properties->type->anyOf[0] = new Schema1();
162
		$properties->type->anyOf[0]->enum = array (
163
		  0 => 'array',
164
		  1 => 'boolean',
165
		  2 => 'integer',
166
		  3 => 'null',
167
		  4 => 'number',
168
		  5 => 'object',
169
		  6 => 'string',
170
		);
171
		$properties->type->anyOf[1] = Schema1::arr();
172
		$properties->type->anyOf[1]->items = new Schema1();
173
		$properties->type->anyOf[1]->items->enum = array (
174
		  0 => 'array',
175
		  1 => 'boolean',
176
		  2 => 'integer',
177
		  3 => 'null',
178
		  4 => 'number',
179
		  5 => 'object',
180
		  6 => 'string',
181
		);
182
		$properties->type->anyOf[1]->minItems = 1;
183
		$properties->type->anyOf[1]->uniqueItems = true;
184
		$properties->items = new Schema1();
185
		$properties->items->anyOf[0] = Schema::schema();
186
		$properties->items->anyOf[1] = Schema1::arr();
187
		$properties->items->anyOf[1]->items = Schema::schema();
188
		$properties->items->anyOf[1]->minItems = 1;
189
		$properties->items->default = new \stdClass();
0 ignored issues
show
Documentation introduced by
The property default does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
190
		$properties->allOf = Schema1::arr();
191
		$properties->allOf->items = Schema::schema();
192
		$properties->allOf->minItems = 1;
193
		$properties->properties = Schema1::object();
194
		$properties->properties->additionalProperties = Schema::schema();
195
		$properties->properties->default = new \stdClass();
0 ignored issues
show
Documentation introduced by
The property default does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
196
		$properties->discriminator = Schema1::string();
197
		$properties->readOnly = Schema1::boolean();
198
		$properties->readOnly->default = false;
0 ignored issues
show
Documentation introduced by
The property default does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
199
		$properties->xml = Xml::schema();
200
		$properties->externalDocs = ExternalDocs::schema();
201
		$properties->example = new Schema1();
202
		$ownerSchema->type = 'object';
0 ignored issues
show
Documentation Bug introduced by
It seems like 'object' of type string is incompatible with the declared type object<Swaggest\JsonSchema\Constraint\Type> 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...
203
		$ownerSchema->additionalProperties = false;
204
		$ownerSchema->patternProperties['^x-'] = new Schema1();
205
		$ownerSchema->patternProperties['^x-']->description = 'Any property starting with x- is valid.';
0 ignored issues
show
Documentation introduced by
The property description does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
206
		$ownerSchema->description = 'A deterministic version of a JSON Schema object.';
0 ignored issues
show
Documentation introduced by
The property description does not exist on object<Swaggest\JsonSchema\Schema>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
207
	}
208
}
209
210