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

Response::hasWarnings()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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