Passed
Push — master ( 2580ba...f9be08 )
by Tomáš
14:54
created

DefaultPackage::getCarrierIdSwap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Inspirum\Balikobot\Model\Package;
6
7
use Inspirum\Arrayable\BaseModel;
8
9
/**
10
 * @extends \Inspirum\Arrayable\BaseModel<string,mixed>
11
 */
12
final class DefaultPackage extends BaseModel implements Package
13
{
14
    /**
15
     * @param array<string> $pieces
16
     */
17 26
    public function __construct(
18
        private readonly string $carrier,
19
        private readonly string $packageId,
20
        private readonly string $batchId,
21
        private readonly string $carrierId,
22
        private readonly ?string $trackUrl = null,
23
        private readonly ?string $labelUrl = null,
24
        private readonly ?string $carrierIdSwap = null,
25
        private readonly array $pieces = [],
26
        private readonly ?string $finalCarrierId = null,
27
        private readonly ?string $finalTrackUrl = null,
28
        private readonly ?string $barcode = null,
29
    ) {
30 26
    }
31
32 13
    public function getPackageId(): string
33
    {
34 13
        return $this->packageId;
35
    }
36
37 2
    public function getBatchId(): string
38
    {
39 2
        return $this->batchId;
40
    }
41
42 1
    public function getTrackUrl(): ?string
43
    {
44 1
        return $this->trackUrl;
45
    }
46
47 1
    public function getLabelUrl(): ?string
48
    {
49 1
        return $this->labelUrl;
50
    }
51
52 1
    public function getCarrierIdSwap(): ?string
53
    {
54 1
        return $this->carrierIdSwap;
55
    }
56
57
    /**
58
     * @return array<string>
59
     */
60 1
    public function getPieces(): array
61
    {
62 1
        return $this->pieces;
63
    }
64
65 1
    public function getFinalCarrierId(): ?string
66
    {
67 1
        return $this->finalCarrierId;
68
    }
69
70 1
    public function getFinalTrackUrl(): ?string
71
    {
72 1
        return $this->finalTrackUrl;
73
    }
74
75
    public function getBarcode(): ?string
76
    {
77
        return $this->barcode;
78
    }
79
80 26
    public function getCarrier(): string
81
    {
82 26
        return $this->carrier;
83
    }
84
85 11
    public function getCarrierId(): string
86
    {
87 11
        return $this->carrierId;
88
    }
89
90
    /** @inheritDoc */
91 3
    public function __toArray(): array
92
    {
93 3
        return [
1 ignored issue
show
Bug Best Practice introduced by
The expression return array('carrier' =...ode' => $this->barcode) returns the type array<string,array|null|string> which is incompatible with the return type mandated by Inspirum\Arrayable\BaseModel::__toArray() of Inspirum\Arrayable\TValue[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
94 3
            'carrier'        => $this->carrier,
95 3
            'carrierId'      => $this->carrierId,
96 3
            'packageId'      => $this->packageId,
97 3
            'batchId'        => $this->batchId,
98 3
            'trackUrl'       => $this->trackUrl,
99 3
            'labelUrl'       => $this->labelUrl,
100 3
            'carrierIdSwap'  => $this->carrierIdSwap,
101 3
            'pieces'         => $this->pieces,
102 3
            'finalCarrierId' => $this->finalCarrierId,
103 3
            'finalTrackUrl'  => $this->finalTrackUrl,
104 3
            'barcode'        => $this->barcode,
105 3
        ];
106
    }
107
}
108