Completed
Push — master ( a904dc...40c607 )
by Joachim
01:50
created

Request::getBody()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.2098

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 4
nop 0
dl 0
loc 13
ccs 5
cts 7
cp 0.7143
crap 3.2098
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Loevgaard\Consignor\ShipmentServer\Request;
3
4
use Loevgaard\Consignor\ShipmentServer\Exception\EncodeJsonException;
5
use Loevgaard\Consignor\ShipmentServer\Response\Response;
6
use function Loevgaard\Consignor\ShipmentServer\encodeJson;
7
8
abstract class Request implements RequestInterface
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $data;
14
15
    /**
16
     * @var array
17
     */
18
    protected $options;
19
20
    /**
21
     * @return array
22
     * @throws EncodeJsonException
23
     */
24 1
    public function getBody() : array
25
    {
26 1
        $body = [];
27 1
        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...
28
            $body['data'] = encodeJson($this->data);
29
        }
30
31 1
        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...
32
            $body['Options'] = encodeJson($this->options);
33
        }
34
35 1
        return $body;
36
    }
37
38 1
    public function getResponseClass(): string
39
    {
40 1
        return Response::class;
41
    }
42
}
43