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

Request   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
dl 0
loc 35
ccs 7
cts 9
cp 0.7778
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getBody() 0 13 3
A getResponseClass() 0 4 1
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