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

AbstractResponse   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 2
cbo 0
dl 0
loc 36
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 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\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