Completed
Branch master (9645b9)
by Neomerx
02:19
created

Error   A

Complexity

Total Complexity 24

Size/Duplication

Total Lines 292
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 292
c 0
b 0
f 0
ccs 63
cts 63
cp 1
rs 10
wmc 24
lcom 3
cbo 0

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 26 2
A getId() 0 4 1
A setId() 0 8 3
A getLinks() 0 4 1
A getTypeLinks() 0 4 1
A setLink() 0 10 2
A setTypeLinks() 0 6 1
A getStatus() 0 4 1
A setStatus() 0 6 1
A getCode() 0 4 1
A setCode() 0 6 1
A getTitle() 0 4 1
A setTitle() 0 6 1
A getDetail() 0 4 1
A setDetail() 0 6 1
A getSource() 0 4 1
A setSource() 0 6 1
A hasMeta() 0 4 1
A getMeta() 0 4 1
A setMeta() 0 7 1
1
<?php declare(strict_types=1);
2
3
namespace Neomerx\JsonApi\Schema;
4
5
/**
6
 * Copyright 2015-2019 [email protected]
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 * http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20
21
use Neomerx\JsonApi\Contracts\Schema\DocumentInterface;
22
use Neomerx\JsonApi\Contracts\Schema\ErrorInterface;
23
use Neomerx\JsonApi\Contracts\Schema\LinkInterface;
24
25
/**
26
 * @package Neomerx\JsonApi
27
 *
28
 * @SuppressWarnings(PHPMD.StaticAccess)
29
 */
30
class Error implements ErrorInterface
31
{
32
    /**
33
     * @var int|string|null
34
     */
35
    private $index;
36
37
    /**
38
     * @var null|iterable
39
     */
40
    private $links;
41
42
    /**
43
     * @var null|iterable
44
     */
45
    private $typeLinks;
46
47
    /**
48
     * @var string|null
49
     */
50
    private $status;
51
52
    /**
53
     * @var string|null
54
     */
55
    private $code;
56
57
    /**
58
     * @var string|null
59
     */
60
    private $title;
61
62
    /**
63
     * @var string|null
64
     */
65
    private $detail;
66
67
    /**
68
     * @var array|null
69
     */
70
    private $source;
71
72
    /**
73
     * @var bool
74
     */
75
    private $hasMeta;
76
77
    /**
78
     * @var mixed
79
     */
80
    private $meta;
81
82
    /**
83
     * @param int|string|null    $idx
84
     * @param LinkInterface|null $aboutLink
85
     * @param iterable|null      $typeLinks
86
     * @param string|null        $status
87
     * @param string|null        $code
88
     * @param string|null        $title
89
     * @param string|null        $detail
90
     * @param array|null         $source
91
     * @param bool               $hasMeta
92
     * @param mixed              $meta
93
     *
94
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
95
     * @SuppressWarnings(PHPMD.ExcessiveParameterList)
96
     */
97 30
    public function __construct(
98
        $idx = null,
99
        LinkInterface $aboutLink = null,
100
        ?iterable $typeLinks = null,
101
        string $status = null,
102
        string $code = null,
103
        string $title = null,
104
        string $detail = null,
105
        array $source = null,
106
        bool $hasMeta = false,
107
        $meta = null
108
    ) {
109
        $this
110 30
            ->setId($idx)
111 30
            ->setLink(DocumentInterface::KEYWORD_ERRORS_ABOUT, $aboutLink)
112 30
            ->setTypeLinks($typeLinks)
113 30
            ->setStatus($status)
114 30
            ->setCode($code)
115 30
            ->setTitle($title)
116 30
            ->setDetail($detail)
117 30
            ->setSource($source);
118
119 30
        if (($this->hasMeta = $hasMeta) === true) {
120 4
            $this->setMeta($meta);
121
        }
122 30
    }
123
124
    /**
125
     * @inheritdoc
126
     */
127 6
    public function getId()
128
    {
129 6
        return $this->index;
130
    }
131
132
    /**
133
     * @param string|int|null $index
134
     *
135
     * @return self
136
     */
137 30
    public function setId($index): self
138
    {
139 30
        assert($index === null || is_int($index) === true || is_string($index) === true);
140
141 30
        $this->index = $index;
142
143 30
        return $this;
144
    }
145
146
    /**
147
     * @inheritdoc
148
     */
149 6
    public function getLinks(): ?iterable
150
    {
151 6
        return $this->links;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->links; of type null|Neomerx\JsonApi\Schema\iterable adds the type Neomerx\JsonApi\Schema\iterable to the return on line 151 which is incompatible with the return type declared by the interface Neomerx\JsonApi\Contract...rrorInterface::getLinks of type null|Neomerx\JsonApi\Contracts\Schema\iterable.
Loading history...
152
    }
153
154
    /**
155
     * @inheritdoc
156
     */
157 6
    public function getTypeLinks(): ?iterable
158
    {
159 6
        return $this->typeLinks;
0 ignored issues
show
Bug Compatibility introduced by
The expression $this->typeLinks; of type null|Neomerx\JsonApi\Schema\iterable adds the type Neomerx\JsonApi\Schema\iterable to the return on line 159 which is incompatible with the return type declared by the interface Neomerx\JsonApi\Contract...Interface::getTypeLinks of type null|Neomerx\JsonApi\Contracts\Schema\iterable.
Loading history...
160
    }
161
162
    /**
163
     * @param string             $name
164
     * @param LinkInterface|null $link
165
     *
166
     * @return self
167
     *
168
     * @SuppressWarnings(PHPMD.ElseExpression)
169
     */
170 30
    public function setLink(string $name, ?LinkInterface $link): self
171
    {
172 30
        if ($link !== null) {
173 4
            $this->links[$name] = $link;
174
        } else {
175 26
            unset($this->links[$name]);
176
        }
177
178 30
        return $this;
179
    }
180
181
    /**
182
     * @param iterable|null $typeLinks
183
     *
184
     * @return self
185
     */
186 30
    public function setTypeLinks(?iterable $typeLinks): self
187
    {
188 30
        $this->typeLinks = $typeLinks;
189
190 30
        return $this;
191
    }
192
193
    /**
194
     * @inheritdoc
195
     */
196 6
    public function getStatus(): ?string
197
    {
198 6
        return $this->status;
199
    }
200
201
    /**
202
     * @param string|null $status
203
     *
204
     * @return self
205
     */
206 30
    public function setStatus(?string $status): self
207
    {
208 30
        $this->status = $status;
209
210 30
        return $this;
211
    }
212
213
    /**
214
     * @inheritdoc
215
     */
216 6
    public function getCode(): ?string
217
    {
218 6
        return $this->code;
219
    }
220
221
    /**
222
     * @param string|null $code
223
     *
224
     * @return self
225
     */
226 30
    public function setCode(?string $code): self
227
    {
228 30
        $this->code = $code;
229
230 30
        return $this;
231
    }
232
233
    /**
234
     * @inheritdoc
235
     */
236 7
    public function getTitle(): ?string
237
    {
238 7
        return $this->title;
239
    }
240
241
    /**
242
     * @param null|string $title
243
     *
244
     * @return self
245
     */
246 30
    public function setTitle(?string $title): self
247
    {
248 30
        $this->title = $title;
249
250 30
        return $this;
251
    }
252
253
    /**
254
     * @inheritdoc
255
     */
256 6
    public function getDetail(): ?string
257
    {
258 6
        return $this->detail;
259
    }
260
261
    /**
262
     * @param null|string $detail
263
     *
264
     * @return self
265
     */
266 30
    public function setDetail(?string $detail): self
267
    {
268 30
        $this->detail = $detail;
269
270 30
        return $this;
271
    }
272
273
    /**
274
     * @inheritdoc
275
     */
276 16
    public function getSource(): ?array
277
    {
278 16
        return $this->source;
279
    }
280
281
    /**
282
     * @param array|null $source
283
     *
284
     * @return self
285
     */
286 30
    public function setSource(?array $source): self
287
    {
288 30
        $this->source = $source;
289
290 30
        return $this;
291
    }
292
293
    /**
294
     * @inheritdoc
295
     */
296 6
    public function hasMeta(): bool
297
    {
298 6
        return $this->hasMeta;
299
    }
300
301
    /**
302
     * @inheritdoc
303
     */
304 4
    public function getMeta()
305
    {
306 4
        return $this->meta;
307
    }
308
309
    /**
310
     * @param mixed|null $meta
311
     *
312
     * @return self
313
     */
314 4
    public function setMeta($meta): self
315
    {
316 4
        $this->hasMeta = true;
317 4
        $this->meta    = $meta;
318
319 4
        return $this;
320
    }
321
}
322