| Total Complexity | 10 |
| Total Lines | 58 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 16 | final class DefaultPackageDataCollection extends BaseCollection implements PackageDataCollection |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @param array<\Inspirum\Balikobot\Model\PackageData\PackageData> $items |
||
| 20 | */ |
||
| 21 | 26 | public function __construct( |
|
| 22 | private string $carrier, |
||
| 23 | array $items = [], |
||
| 24 | ) { |
||
| 25 | 26 | parent::__construct([]); |
|
| 26 | |||
| 27 | 26 | foreach ($items as $package) { |
|
| 28 | 21 | $this->add($package); |
|
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 32 | 21 | public function getCarrier(): string |
|
| 35 | } |
||
| 36 | |||
| 37 | /** @inheritDoc */ |
||
| 38 | 1 | public function getPackages(): array |
|
| 39 | { |
||
| 40 | 1 | return $this->getItems(); |
|
| 41 | } |
||
| 42 | |||
| 43 | 24 | public function add(PackageData $item): void |
|
| 44 | { |
||
| 45 | 24 | $this->offsetAdd($item); |
|
| 46 | } |
||
| 47 | |||
| 48 | /** @inheritDoc */ |
||
| 49 | 1 | public function offsetSet(mixed $key, mixed $value): void |
|
| 52 | } |
||
| 53 | |||
| 54 | /** @inheritDoc */ |
||
| 55 | 25 | public function offsetAdd(mixed $value): void |
|
| 56 | { |
||
| 57 | 25 | parent::offsetAdd($this->clonePackageWithEid($value)); |
|
| 58 | } |
||
| 59 | |||
| 60 | 26 | private function clonePackageWithEid(PackageData $package): PackageData |
|
| 61 | { |
||
| 62 | 26 | $package = clone $package; |
|
| 63 | |||
| 64 | 26 | if ($package->hasEID() === false) { |
|
| 65 | 24 | $package->setEID($this->newEID()); |
|
| 66 | } |
||
| 67 | |||
| 68 | 26 | return $package; |
|
| 69 | } |
||
| 70 | |||
| 71 | 24 | private function newEID(): string |
|
| 74 | } |
||
| 75 | } |
||
| 76 |