Completed
Pull Request — master (#9)
by Hugo
01:41
created

AbstractResponse::getWarnings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yproximite\Api\Response;
6
7
class AbstractResponse
8
{
9
    /** @var array|null */
10
    protected $data;
11
    /** @var array */
12
    protected $errors;
13
    /** @var array */
14
    protected $warnings;
15
16
    public function __construct(array $payload)
17
    {
18
        $this->data     = $payload['data'] ?? null;
19
        $this->errors   = $payload['errors'] ?? [];
20
        $this->warnings = $payload['extensions']['warnings'] ?? [];
21
    }
22
23
    public function hasErrors(): bool
24
    {
25
        return \count($this->errors) > 0;
26
    }
27
28
    public function getErrors(): array
29
    {
30
        return $this->errors;
31
    }
32
33
    public function hasWarnings(): bool
34
    {
35
        return \count($this->warnings) > 0;
36
    }
37
38
    public function getWarnings(): array
39
    {
40
        return $this->warnings;
41
    }
42
}
43