Completed
Pull Request — master (#2)
by Paulius
02:11 queued 41s
created

LabelsRequest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getTrackingNumbers() 0 3 1
A getCountry() 0 3 1
A toArray() 0 5 1
1
<?php
2
3
namespace DPD\Interconnector\Request;
4
5
use DPD\Interconnector\Authentication;
6
7
class LabelsRequest implements RequestInterface
8
{
9
    private $authentication;
10
11
    private $trackingNumbers = [];
12
13
    private $printInfo = [];
14
15
    public function __construct(Authentication $authentication, array $trackingNumbers, string $printType, string $printFormat)
16
    {
17
        $this->authentication = $authentication;
18
        $this->trackingNumbers = $trackingNumbers;
19
        $this->printInfo = [
20
            'type' => $printType,
21
            'format' => $printFormat
22
        ];
23
    }
24
25
    public function toArray(): array
26
    {
27
        return array_merge(
28
            $this->authentication->toArray(),
29
            ['parcels' => $this->getTrackingNumbers(), 'printType' => $this->printInfo['type'], 'printFormat' => $this->printInfo['format']]
30
        );
31
    }
32
33
    public function getTrackingNumbers(): string
34
    {
35
        return implode('|', $this->trackingNumbers);
36
    }
37
38
    public function getCountry(): string
39
    {
40
        $this->authentication->country;
0 ignored issues
show
Bug Best Practice introduced by
In this branch, the function will implicitly return null which is incompatible with the type-hinted return string. Consider adding a return statement or allowing null as return value.

For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example:

interface ReturnsInt {
    public function returnsIntHinted(): int;
}

class MyClass implements ReturnsInt {
    public function returnsIntHinted(): int
    {
        if (foo()) {
            return 123;
        }
        // here: null is implicitly returned
    }
}
Loading history...
41
    }
42
}