Completed
Push — master ( 37427d...780143 )
by Dmitry
02:21
created

Response::getUnitsRest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 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 2
    public function __construct(array $responseAttributes)
30
    {
31 2
        $this->setOptions($responseAttributes);
32 2
    }
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 1
    public function getUnits()
58
    {
59 1
        return $this->units;
60
    }
61
62
    /**
63
     * @param string $rawUnits
64
     * @throws InvalidArgumentException
65
     */
66 2
    public function setUnits($rawUnits)
67
    {
68 2
        $units = explode('/', $rawUnits);
69 2
        if (is_array($units)
70 2
            && count($units) > 0
71 2
        ) {
72 2
            $this->units = $units;
73 2
        }
74 2
    }
75
76
    /**
77
     * @inheritdoc
78
     */
79 1
    public function getRequestId()
80
    {
81 1
        return $this->requestId;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87 1
    public function getUnitsDebit()
88
    {
89 1
        return $this->getUnits()[self::UNITS_TYPE_DEBIT];
90
    }
91
92
    /**
93
     * @inheritdoc
94
     */
95 1
    public function getUnitsRest()
96
    {
97 1
        return $this->getUnits()[self::UNITS_TYPE_REST];
98
    }
99
100
    /**
101
     * @inheritdoc
102
     */
103 1
    public function getUnitsLimit()
104
    {
105 1
        return $this->getUnits()[self::UNITS_TYPE_LIMIT];
106
    }
107
108
    /**
109
     * @inheritdoc
110
     */
111 2
    public function getBody()
112
    {
113 2
        return $this->body;
114
    }
115
116
    /**
117
     * @inheritdoc
118
     */
119 1
    public function getHeaders()
120
    {
121 1
        return $this->headers;
122
    }
123
}
124