Passed
Pull Request — master (#34)
by Anatoly
02:26
created

Schema   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 12
c 1
b 0
f 0
dl 0
loc 38
ccs 0
cts 13
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 17 4
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2018, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/http-router/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/http-router
10
 */
11
12
namespace Sunrise\Http\Router\Annotation\OpenApi;
13
14
/**
15
 * @Annotation
16
 *
17
 * @Target({"ANNOTATION", "CLASS"})
18
 */
19
final class Schema
20
{
21
22
    /**
23
     * @var string
24
     */
25
    public $ref;
26
27
    /**
28
     * @var string
29
     */
30
    public $type;
31
32
    /**
33
     * @var array<Sunrise\Http\Router\Annotation\OpenApi\Property>
34
     */
35
    public $properties = [];
36
37
    /**
38
     * @return array
39
     */
40
    public function toArray() : array
41
    {
42
        $result = [];
43
44
        if (isset($this->ref)) {
45
            $result['$ref'] = $this->ref;
46
        }
47
48
        if (isset($this->type)) {
49
            $result['type'] = $this->type;
50
        }
51
52
        foreach ($this->properties as $value) {
53
            $result['properties'][$value->name] = $value->toArray();
54
        }
55
56
        return $result;
57
    }
58
}
59