RequestDefinition::getHeadersSchema()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 1
cts 1
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
namespace ElevenLabs\Api\Definition;
3
4
class RequestDefinition implements \Serializable, MessageDefinition
5
{
6
    /** @var string */
7
    private $method;
8
9
    /** @var string */
10
    private $operationId;
11
12
    /** @var string */
13
    private $pathTemplate;
14
15
    /** @var Parameters */
16
    private $parameters;
17
18
    /** @var array */
19
    private $contentTypes;
20
21
    /** @var ResponseDefinition[] */
22
    private $responses;
23
24
    /**
25
     * @param string $method
26
     * @param string $operationId
27
     * @param string $pathTemplate
28
     * @param Parameters $parameters
29 17
     * @param array $contentTypes
30
     * @param ResponseDefinition[] $responses
31
     */
32
    public function __construct($method, $operationId, $pathTemplate, Parameters $parameters, array $contentTypes, array $responses)
33
    {
34
        $this->method = $method;
35
        $this->operationId = $operationId;
36
        $this->pathTemplate = $pathTemplate;
37 17
        $this->parameters = $parameters;
38 17
        $this->contentTypes = $contentTypes;
39 17
        foreach ($responses as $response) {
40 17
            $this->addResponseDefinition($response);
41 17
        }
42 17
    }
43 15
44
    /**
45 17
     * @return string
46
     */
47 1
    public function getMethod()
48
    {
49 1
        return $this->method;
50
    }
51
52 13
    /**
53
     * @return string
54 13
     */
55
    public function getOperationId()
56
    {
57 1
        return $this->operationId;
58
    }
59 1
60
    /**
61
     * @return string
62 5
     */
63
    public function getPathTemplate()
64 5
    {
65
        return $this->pathTemplate;
66
    }
67 3
68
    /**
69 3
     * @return Parameters
70
     */
71
    public function getRequestParameters()
72 6
    {
73
        return $this->parameters;
74 6
    }
75 4
76
    /**
77
     * Supported content types
78 2
     *
79 1
     * @return array
80
     */
81
    public function getContentTypes()
82 1
    {
83 1
        return $this->contentTypes;
84 1
    }
85 1
86 1
    /**
87 1
     * @param $statusCode
88
     * @return ResponseDefinition
89
     */
90
    public function getResponseDefinition($statusCode)
91
    {
92 1
        if (isset($this->responses[$statusCode])) {
93
            return $this->responses[$statusCode];
94 1
        } else if (isset($this->responses['default'])) {
95
            return $this->responses['default'];
96
        } else {
97
            throw new \InvalidArgumentException(
98
                sprintf(
99
                    'No response definition for %s %s is available for status code %s',
100
                    $this->method,
101
                    $this->pathTemplate,
102 1
                    $statusCode
103
                )
104 1
            );
105
        }
106
    }
107
108
    public function hasBodySchema()
109
    {
110
        return $this->parameters->hasBodySchema();
111
    }
112
113
    public function getBodySchema()
114
    {
115
        return $this->parameters->getBodySchema();
116
    }
117
118
    public function hasHeadersSchema()
119
    {
120
        return $this->parameters->hasHeadersSchema();
121
    }
122 1
123
    public function getHeadersSchema()
124 1
    {
125
        return $this->parameters->getHeadersSchema();
126
    }
127
128
    public function hasQueryParametersSchema()
129
    {
130
        return $this->parameters->hasQueryParametersSchema();
131
    }
132
133 1
    public function getQueryParametersSchema()
134
    {
135 1
        return $this->parameters->getQueryParametersSchema();
136 1
    }
137 1
138 1
    private function addResponseDefinition(ResponseDefinition $response)
139 1
    {
140 1
        $this->responses[$response->getStatusCode()] = $response;
141 1
    }
142
143
    public function serialize()
144
    {
145
        return serialize([
146 1
            'method' => $this->method,
147
            'operationId' => $this->operationId,
148 1
            'pathTemplate' => $this->pathTemplate,
149 1
            'parameters' => $this->parameters,
150 1
            'contentTypes' => $this->contentTypes,
151 1
            'responses' => $this->responses
152 1
        ]);
153 1
    }
154 1
155 1
    public function unserialize($serialized)
156
    {
157 15
        $data = unserialize($serialized);
158
        $this->method = $data['method'];
159 15
        $this->operationId = $data['operationId'];
160 15
        $this->pathTemplate = $data['pathTemplate'];
161
        $this->parameters = $data['parameters'];
162
        $this->contentTypes = $data['contentTypes'];
163
        $this->responses = $data['responses'];
164
    }
165
}
166