Total Complexity | 10 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
11 | class Collection implements Countable |
||
12 | { |
||
13 | /** @var Item[] */ |
||
14 | private $list; |
||
15 | |||
16 | public function __construct(array $list) |
||
17 | { |
||
18 | Assertion::allIsInstanceOf($list, InitialItem::class); |
||
19 | } |
||
20 | |||
21 | public function replace(FinalItem $finalShard): void |
||
22 | { |
||
23 | /** @var Item $shard */ |
||
24 | $list = $this->list; |
||
25 | $listUuid = []; |
||
26 | foreach ($list as $key => $shard) { |
||
27 | if ($shard instanceof FinalItem) { |
||
28 | continue; |
||
29 | } |
||
30 | $listUuid[] = $shard->getUuid()->getValue(); |
||
31 | if ($shard->getUuid()->equal($finalShard->getUuid()) |
||
32 | && $shard->getProfile()->equal($finalShard->getProfile())) { |
||
33 | $list[$key] = $finalShard; |
||
34 | $this->list = $list; |
||
35 | return; |
||
36 | } |
||
37 | } |
||
38 | |||
39 | throw new InvalidUuidComparisonOnReplaceException( |
||
40 | sprintf( |
||
41 | 'Could not find initial shard by uuid %s in given collection: %s', |
||
42 | $finalShard->getUuid()->getValue(), |
||
43 | join(',', $listUuid) |
||
44 | ) |
||
45 | ); |
||
46 | } |
||
47 | |||
48 | public function count(): int |
||
49 | { |
||
50 | return count($this->list); |
||
51 | } |
||
52 | |||
53 | public function isAllShardsFinishedProgress(): bool |
||
61 | } |
||
62 | } |
||
63 |