inspirum /
balikobot-php
| 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 readonly string $carrier, |
||
| 18 | private readonly string $carrierId, |
||
| 19 | private readonly 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 | 1 | 'Item carrier ID mismatch ("%s" instead "%s")', |
|
| 35 | 1 | $item->getCarrierId(), |
|
| 36 | 1 | $this->carrierId, |
|
| 37 | 1 | ), |
|
| 38 | 1 | ); |
|
| 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 | 1 | return [ |
|
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 63 | 1 | 'carrier' => $this->carrier, |
|
| 64 | 1 | 'carrierId' => $this->carrierId, |
|
| 65 | 1 | 'states' => $this->states->__toArray(), |
|
| 66 | 1 | ]; |
|
| 67 | } |
||
| 68 | } |
||
| 69 |