Completed
Push — master ( 85a630...b97b88 )
by Dmitry
02:41
created

TransportResponse::getBody()   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 TransportResponse
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
     * TransportResponse constructor.
26
     *
27
     * @param array $options
28
     */
29 1
    public function __construct(array $options)
30
    {
31 1
        $this->setOptions($options);
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
    /**
78
     * @return string
79
     */
80
    public function getRequestId()
81
    {
82
        return $this->requestId;
83
    }
84
85
    /**
86
     * @return int
87
     */
88
    public function getUnitsDebit()
89
    {
90
        return $this->getUnits()[self::UNITS_TYPE_DEBIT];
91
    }
92
93
    /**
94
     * @return int
95
     */
96
    public function getUnitsRest()
97
    {
98
        return $this->getUnits()[self::UNITS_TYPE_REST];
99
    }
100
101
    /**
102
     * @return int
103
     */
104
    public function getUnitsLimit()
105
    {
106
        return $this->getUnits()[self::UNITS_TYPE_LIMIT];
107
    }
108
109
    /**
110
     * @return string
111
     */
112 1
    public function getBody()
113
    {
114 1
        return $this->body;
115
    }
116
117
    /**
118
     * The keys represent the header name as it will be sent over the wire, and
119
     * each value is an array of strings associated with the header.
120
     *
121
     *     // Represent the headers as a string
122
     *     foreach ($message->getHeaders() as $name => $values) {
123
     *         echo $name . ": " . implode(", ", $values);
124
     *     }
125
     *
126
     * @return array
127
     */
128 1
    public function getHeaders()
129
    {
130 1
        return $this->headers;
131
    }
132
}
133