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

Response::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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