Completed
Push — master ( ad0b2c...f5bffe )
by Joachim
05:31
created

Request::getHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Loevgaard\Consignor\ShipmentServer\Request;
3
4
use function Loevgaard\Consignor\ShipmentServer\encodeJson;
5
use Loevgaard\Consignor\ShipmentServer\Exception\EncodeJsonException;
6
7
abstract class Request implements RequestInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    protected $data;
13
14
    /**
15
     * @var array
16
     */
17
    protected $options;
18
19
    public function getHeaders() : array
20
    {
21
        return [];
22
    }
23
24
    /**
25
     * @return array
26
     * @throws EncodeJsonException
27
     */
28
    public function getBody() : array
29
    {
30
        $body = [];
31
        if($this->data) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->data of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
32
            $body['data'] = encodeJson($this->data);
33
        }
34
35
        if($this->options) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $this->options of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
36
            $body['Options'] = encodeJson($this->options);
37
        }
38
39
        return $body;
40
    }
41
}