Completed
Push — master ( f5bffe...9f8e49 )
by Joachim
04:21
created

Request   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 5
cts 7
cp 0.7143
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A getBody() 0 13 3
1
<?php
2
namespace Loevgaard\Consignor\ShipmentServer\Request;
3
4
use Loevgaard\Consignor\ShipmentServer\Exception\EncodeJsonException;
5
use function Loevgaard\Consignor\ShipmentServer\encodeJson;
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
    /**
20
     * @return array
21
     * @throws EncodeJsonException
22
     */
23 1
    public function getBody() : array
24
    {
25 1
        $body = [];
26 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...
27
            $body['data'] = encodeJson($this->data);
28
        }
29
30 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...
31
            $body['Options'] = encodeJson($this->options);
32
        }
33
34 1
        return $body;
35
    }
36
}
37