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

Header   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 3
dl 0
loc 119
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A setUpProperties() 0 60 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 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;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, Swaggest\JsonSchema\SwaggerSchema\Schema.

Let’s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let’s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
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 Schema $ownerSchema
71
	 */
72
	public static function setUpProperties($properties, Schema $ownerSchema)
73
	{
74
		$properties->type = Schema::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 = Schema::string();
83
		$properties->items = PrimitivesItems::schema();
84
		$properties->collectionFormat = Schema::string();
85
		$properties->collectionFormat->default = 'csv';
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...
86
		$properties->collectionFormat->enum = array (
87
		  0 => 'csv',
88
		  1 => 'ssv',
89
		  2 => 'tsv',
90
		  3 => 'pipes',
91
		);
92
		$properties->default = new Schema();
93
		$properties->maximum = Schema::number();
94
		$properties->exclusiveMaximum = Schema::boolean();
95
		$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...
96
		$properties->minimum = Schema::number();
97
		$properties->exclusiveMinimum = Schema::boolean();
98
		$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...
99
		$properties->maxLength = Schema::integer();
100
		$properties->maxLength->minimum = 0;
101
		$properties->minLength = new Schema();
102
		$properties->minLength->allOf[0] = Schema::integer();
103
		$properties->minLength->allOf[0]->minimum = 0;
104
		$properties->minLength->allOf[1] = new Schema();
105
		$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...
106
		$properties->pattern = Schema::string();
107
		$properties->pattern->format = 'regex';
108
		$properties->maxItems = Schema::integer();
109
		$properties->maxItems->minimum = 0;
110
		$properties->minItems = new Schema();
111
		$properties->minItems->allOf[0] = Schema::integer();
112
		$properties->minItems->allOf[0]->minimum = 0;
113
		$properties->minItems->allOf[1] = new Schema();
114
		$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...
115
		$properties->uniqueItems = Schema::boolean();
116
		$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...
117
		$properties->enum = Schema::arr();
118
		$properties->enum->minItems = 1;
119
		$properties->enum->uniqueItems = true;
120
		$properties->multipleOf = Schema::number();
121
		$properties->multipleOf->minimum = 0;
122
		$properties->multipleOf->exclusiveMinimum = true;
123
		$properties->description = Schema::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 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...
125
		$ownerSchema->additionalProperties = false;
126
		$ownerSchema->patternProperties['^x-'] = new Schema();
127
		$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...
128
		$ownerSchema->required = array (
129
		  0 => 'type',
130
		);
131
	}
132
}
133
134