Passed
Branch master (0d8fc3)
by Tomáš
12:26
created

DefaultStatuses::getCarrier()   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 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
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\Status;
6
7
use Inspirum\Arrayable\BaseModel;
8
use InvalidArgumentException;
9
use function sprintf;
10
11
/**
12
 * @extends \Inspirum\Arrayable\BaseModel<string,mixed>
13
 */
14
final class DefaultStatuses extends BaseModel implements Statuses
15
{
16 6
    public function __construct(
17
        private string $carrier,
18
        private string $carrierId,
19
        private StatusCollection $states,
20
    ) {
21 6
        foreach ($states as $status) {
22 6
            $this->validateCarrierId($status);
23
        }
24
    }
25
26
    /**
27
     * @throws \InvalidArgumentException
28
     */
29 6
    private function validateCarrierId(Status $item): void
30
    {
31 6
        if ($this->carrierId !== $item->getCarrierId()) {
32 1
            throw new InvalidArgumentException(
33 1
                sprintf(
34
                    'Item carrier ID mismatch ("%s" instead "%s")',
35 1
                    $item->getCarrierId(),
36 1
                    $this->carrierId,
37
                )
38
            );
39
        }
40
    }
41
42 4
    public function getCarrier(): string
43
    {
44 4
        return $this->carrier;
45
    }
46
47 1
    public function getCarrierId(): string
48
    {
49 1
        return $this->carrierId;
50
    }
51
52 1
    public function getStates(): StatusCollection
53
    {
54 1
        return $this->states;
55
    }
56
57
    /**
58
     * @return array<string,string|array<int,array<string,mixed>>>
59
     */
60 1
    public function __toArray(): array
61
    {
62
        return [
0 ignored issues
show
Bug Best Practice introduced by
The expression return array('carrier' =...s->states->__toArray()) returns an array which contains values of type Inspirum\Arrayable\TValue[] which are incompatible with the documented value type array<integer,array<string,mixed>>|string.
Loading history...
63 1
            'carrier'   => $this->carrier,
64 1
            'carrierId' => $this->carrierId,
65 1
            'states'    => $this->states->__toArray(),
66
        ];
67
    }
68
}
69