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

Operation   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 20
c 0
b 0
f 0
dl 0
loc 63
ccs 0
cts 18
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 22 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({"CLASS"})
18
 */
19
final class Operation
20
{
21
22
    /**
23
     * @var array<string>
24
     */
25
    public $tags = [];
26
27
    /**
28
     * @var string
29
     */
30
    public $summary = '';
31
32
    /**
33
     * @var string
34
     */
35
    public $description = '';
36
37
    /**
38
     * @var bool
39
     */
40
    public $deprecated = false;
41
42
    /**
43
     * @var array<Sunrise\Http\Router\Annotation\OpenApi\Parameter>
44
     */
45
    public $parameters = [];
46
47
    /**
48
     * @var Sunrise\Http\Router\Annotation\OpenApi\RequestBody
0 ignored issues
show
Bug introduced by
The type Sunrise\Http\Router\Anno...ion\OpenApi\RequestBody was not found. Did you mean Sunrise\Http\Router\Annotation\OpenApi\RequestBody? If so, make sure to prefix the type with \.
Loading history...
49
     */
50
    public $requestBody;
51
52
    /**
53
     * @var array<Sunrise\Http\Router\Annotation\OpenApi\Response>
54
     */
55
    public $responses = [];
56
57
    /**
58
     * @return array
59
     */
60
    public function toArray() : array
61
    {
62
        $result = [
63
            'tags' => $this->tags,
64
            'summary' => $this->summary,
65
            'description' => $this->description,
66
            'deprecated' => $this->deprecated,
67
        ];
68
69
        foreach ($this->parameters as $value) {
70
            $result['parameters'][] = $value->toArray();
71
        }
72
73
        if (isset($this->requestBody)) {
74
            $result['requestBody'] = $this->requestBody->toArray();
75
        }
76
77
        foreach ($this->responses as $value) {
78
            $result['responses'][$value->code] = $value->toArray();
79
        }
80
81
        return $result;
82
    }
83
}
84