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

Schema::toArray()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 17
ccs 0
cts 13
cp 0
rs 10
cc 4
nc 8
nop 0
crap 20
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