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

Oauth2AccessCodeSecurity   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 2
dl 0
loc 52
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B setUpProperties() 0 28 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 Oauth2AccessCodeSecurity extends ClassStructure {
15
	/** @var string */
16
	public $type;
17
18
	/** @var string */
19
	public $flow;
20
21
	/** @var string[] */
22
	public $scopes;
23
24
	/** @var string */
25
	public $authorizationUrl;
26
27
	/** @var string */
28
	public $tokenUrl;
29
30
	/** @var string */
31
	public $description;
32
33
	/**
34
	 * @param Properties|static $properties
35
	 * @param Schema $ownerSchema
36
	 */
37
	public static function setUpProperties($properties, Schema $ownerSchema)
38
	{
39
		$properties->type = Schema::string();
40
		$properties->type->enum = array (
41
		  0 => 'oauth2',
42
		);
43
		$properties->flow = Schema::string();
44
		$properties->flow->enum = array (
45
		  0 => 'accessCode',
46
		);
47
		$properties->scopes = Schema::object();
48
		$properties->scopes->additionalProperties = Schema::string();
49
		$properties->authorizationUrl = Schema::string();
50
		$properties->authorizationUrl->format = 'uri';
51
		$properties->tokenUrl = Schema::string();
52
		$properties->tokenUrl->format = 'uri';
53
		$properties->description = Schema::string();
54
		$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...
55
		$ownerSchema->additionalProperties = false;
56
		$ownerSchema->patternProperties['^x-'] = new Schema();
57
		$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...
58
		$ownerSchema->required = array (
59
		  0 => 'type',
60
		  1 => 'flow',
61
		  2 => 'authorizationUrl',
62
		  3 => 'tokenUrl',
63
		);
64
	}
65
}
66
67