| Conditions | 6 |
| Paths | 12 |
| Total Lines | 29 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 16 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 23 | 5 | public function handle(array $tiles, Target $target, Step $stepStruct): void |
|
| 24 | { |
||
| 25 | 5 | $allVents = []; |
|
| 26 | |||
| 27 | 5 | foreach ($tiles as $key => $tile) { |
|
| 28 | 5 | if (!($tile instanceof VentTile)) { |
|
| 29 | 5 | continue; |
|
| 30 | } |
||
| 31 | |||
| 32 | 4 | $allVents[] = (int) $key; |
|
| 33 | } |
||
| 34 | |||
| 35 | 5 | $nextVentIndex = 0; |
|
| 36 | 5 | $totalVents = count($allVents); |
|
| 37 | 5 | foreach ($allVents as $ventKey => $ventIndex) { |
|
| 38 | 4 | if ($ventIndex !== $stepStruct->getCurrentIndex()) { |
|
| 39 | 4 | continue; |
|
| 40 | } |
||
| 41 | |||
| 42 | 4 | $ventKey = (int) $ventKey; |
|
| 43 | // Currently active vent is last vent |
||
| 44 | 4 | if ($ventKey + 1 === $totalVents) { |
|
| 45 | 2 | $nextVentIndex = $allVents[0]; |
|
| 46 | } else { |
||
| 47 | 4 | $nextVentIndex = $allVents[$ventKey + 1]; |
|
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | 5 | $stepStruct->setCurrentIndex($nextVentIndex); |
|
| 52 | 5 | } |
|
| 54 |