Completed
Pull Request — master (#9)
by Viacheslav
13:47
created

Tag::setUpProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 2
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 JsonBasicSchema;
11
use Swaggest\JsonSchema\Structure\ClassStructure;
12
13
14
class Tag extends ClassStructure {
15
	/** @var string */
16
	public $name;
17
18
	/** @var string */
19
	public $description;
20
21
	/** @var ExternalDocs information about external documentation */
22
	public $externalDocs;
23
24
	/**
25
	 * @param Properties|static $properties
26
	 * @param JsonBasicSchema $ownerSchema
27
	 */
28
	public static function setUpProperties($properties, JsonBasicSchema $ownerSchema)
29
	{
30
		$properties->name = JsonBasicSchema::string();
31
		$properties->description = JsonBasicSchema::string();
32
		$properties->externalDocs = ExternalDocs::schema();
33
		$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...
34
		$ownerSchema->additionalProperties = false;
35
		$ownerSchema->patternProperties['^x-'] = new JsonBasicSchema();
36
		$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...
37
		$ownerSchema->required = array (
38
		  0 => 'name',
39
		);
40
	}
41
}
42
43