Completed
Pull Request — master (#5)
by Dmitry
05:48
created

Response   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 108
ccs 15
cts 25
cp 0.6
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getUnits() 0 4 1
A setUnits() 0 9 3
A getRequestId() 0 4 1
A getUnitsDebit() 0 4 1
A getUnitsRest() 0 4 1
A getUnitsLimit() 0 4 1
A getBody() 0 4 1
A getHeaders() 0 4 1
1
<?php
2
/**
3
 * @author Dmitry Gladyshev <[email protected]>
4
 * @date 17/08/2016 13:44
5
 */
6
7
namespace Yandex\Direct\Transport;
8
9
use Yandex\Direct\ConfigurableTrait;
10
use Yandex\Direct\Exception\InvalidArgumentException;
11
12
/**
13
 * Class TransportRequest
14
 * @package Yandex\Direct
15
 */
16
class Response implements ResponseInterface
17
{
18
    use ConfigurableTrait;
19
20
    const UNITS_TYPE_DEBIT  = 0;
21
    const UNITS_TYPE_REST   = 1;
22
    const UNITS_TYPE_LIMIT  = 2;
23
24
    /**
25
     * Response constructor.
26
     *
27
     * @param array $responseAttributes
28
     */
29 1
    public function __construct(array $responseAttributes)
30
    {
31 1
        $this->setOptions($responseAttributes);
32 1
    }
33
34
    /**
35
     * @var array
36
     */
37
    protected $units = [null, null, null];
38
39
    /**
40
     * @var string
41
     */
42
    protected $requestId;
43
44
    /**
45
     * @var string
46
     */
47
    protected $body;
48
49
    /**
50
     * @var array
51
     */
52
    protected $headers = [];
53
54
    /**
55
     * @return array
56
     */
57
    public function getUnits()
58
    {
59
        return $this->units;
60
    }
61
62
    /**
63
     * @param string $rawUnits
64
     * @throws InvalidArgumentException
65
     */
66 1
    public function setUnits($rawUnits)
67
    {
68 1
        $units = explode('/', $rawUnits);
69 1
        if (is_array($units)
70 1
            && count($units) > 0
71 1
        ) {
72 1
            $this->units = $units;
73 1
        }
74 1
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79
    public function getRequestId()
80
    {
81
        return $this->requestId;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87
    public function getUnitsDebit()
88
    {
89
        return $this->getUnits()[self::UNITS_TYPE_DEBIT];
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95
    public function getUnitsRest()
96
    {
97
        return $this->getUnits()[self::UNITS_TYPE_REST];
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103
    public function getUnitsLimit()
104
    {
105
        return $this->getUnits()[self::UNITS_TYPE_LIMIT];
106
    }
107
108
    /**
109
     * @inheritdoc
110
     */
111 1
    public function getBody()
112
    {
113 1
        return $this->body;
114
    }
115
116
    /**
117
     * @inheritdoc
118
     */
119 1
    public function getHeaders()
120
    {
121 1
        return $this->headers;
122
    }
123
}
124