VentTileHandler   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 39
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 7

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 1
A handle() 0 29 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PanicLabCore\Services\Handlers;
6
7
use function count;
8
use PanicLabCore\Structs\Step;
9
use PanicLabCore\Structs\Target;
10
use PanicLabCore\Structs\Tile;
11
use PanicLabCore\Structs\VentTile;
12
13
class VentTileHandler implements TileHandlerInterface
14
{
15 5
    public function supports(Tile $tile): bool
16
    {
17 5
        return $tile instanceof VentTile;
18
    }
19
20
    /**
21
     * @param Tile[] $tiles
22
     */
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
    }
53
}
54