Passed
Branch release/v2.0.0 (272d59)
by Anatoly
06:01 queued 02:10
created

Encoding   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 17
dl 0
loc 64
ccs 0
cts 18
cp 0
rs 10
c 1
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 23 5
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"})
18
 *
19
 * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#encoding-object
20
 */
21
final class Encoding extends AbstractAnnotation implements EncodingInterface
22
{
23
24
    /**
25
     * @var string
26
     *
27
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-encodingcontenttype
28
     */
29
    public $contentType;
30
31
    /**
32
     * @var array<\Sunrise\Http\Router\Annotation\OpenApi\HeaderInterface>
33
     *
34
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-encodingheaders
35
     */
36
    public $headers = [];
37
38
    /**
39
     * @var string
40
     *
41
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-encodingstyle
42
     */
43
    public $style;
44
45
    /**
46
     * @var bool
47
     *
48
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-encodingexplode
49
     */
50
    public $explode;
51
52
    /**
53
     * @var bool
54
     *
55
     * @link https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#user-content-encodingallowreserved
56
     */
57
    public $allowReserved = false;
58
59
    /**
60
     * {@inheritDoc}
61
     */
62
    public function toArray() : array
63
    {
64
        $result = [
65
            'allowReserved' => $this->allowReserved,
66
        ];
67
68
        if (isset($this->contentType)) {
69
            $result['contentType'] = $this->contentType;
70
        }
71
72
        foreach ($this->headers as $key => $value) {
73
            $result['headers'][$key] = $value->toArray();
74
        }
75
76
        if (isset($this->style)) {
77
            $result['style'] = $this->style;
78
        }
79
80
        if (isset($this->explode)) {
81
            $result['explode'] = $this->explode;
82
        }
83
84
        return $result;
85
    }
86
}
87