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

Response   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 2
cbo 0
dl 0
loc 41
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A getData() 0 4 1
A hasErrors() 0 4 1
A getErrors() 0 4 1
A hasWarnings() 0 4 1
A getWarnings() 0 4 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