Response   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 37
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A isSuccessful() 0 4 2
A getError() 0 4 2
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
    /**
14
     * @var int
15
     */
16
    protected $status;
17
18 2
    public function __construct(array $data)
19
    {
20 2
        Assert::that($data)->keyExists('status');
21
22 2
        $this->data = $data;
23 2
        $this->status = (int)$this->data['status'];
24
25 2
        if ($this->isSuccessful()) {
26 1
            $this->init();
27
        }
28 2
    }
29
30
    /**
31
     * @return bool
32
     */
33 2
    public function isSuccessful(): bool
34
    {
35 2
        return $this->status >= 200 && $this->status < 300;
36
    }
37
38 1
    public function getError(): string
39
    {
40 1
        return $this->isSuccessful() ? '' : $this->data['message'];
41
    }
42
}
43