Completed
Push — master ( 737d23...df8264 )
by Joachim
04:33
created

Response::getError()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 0
cp 0
rs 10
c 0
b 0
f 0
cc 2
eloc 2
nc 2
nop 0
crap 6
1
<?php declare(strict_types=1);
2
namespace Loevgaard\Linkmobility\Response;
3
4
use Assert\Assert;
5
6
abstract class Response implements ResponseInterface
7
{
8
    /**
9
     * @var array
10
     */
11
    protected $data;
12
13 1
    /**
14
     * @var int
15 1
     */
16 1
    protected $status;
17
18 1
    public function __construct(array $data)
19
    {
20
        Assert::that($data)->keyExists('status');
21 1
22
        $this->data = $data;
23 1
        $this->status = (int)$this->data['status'];
24
25
        if ($this->isSuccessful()) {
26
            $this->init();
27
        }
28
    }
29
30
    /**
31
     * @return bool
32
     */
33
    public function isSuccessful(): bool
34
    {
35
        return $this->status >= 200 && $this->status < 300;
36
    }
37
38
    public function getError(): string
39
    {
40
        return $this->isSuccessful() ? '' : $this->data['message'];
41
    }
42
}
43