Passed
Push — dev ( c878e4...99122a )
by Janko
30:05
created

ShipDestruction::destroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
nc 1
nop 4
dl 0
loc 20
ccs 0
cts 14
cp 0
crap 2
rs 9.8333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib\Destruction;
6
7
use Stu\Lib\Information\InformationInterface;
8
use Stu\Module\Ship\Lib\Destruction\Handler\ShipDestructionHandlerInterface;
9
use Stu\Module\Ship\Lib\ShipWrapperInterface;
10
11
final class ShipDestruction implements ShipDestructionInterface
12
{
13
14
    /**
15
     * @param array<ShipDestructionHandlerInterface> $destructionHandlers
16
     */
17 1
    public function __construct(
18
        private array $destructionHandlers
19
    ) {
20 1
    }
21
22
    public function destroy(
23
        ?ShipDestroyerInterface $destroyer,
24
        ShipWrapperInterface $destroyedShipWrapper,
25
        ShipDestructionCauseEnum $cause,
26
        InformationInterface $informations
27
    ): void {
28
29
        array_walk(
30
            $this->destructionHandlers,
31
            function (ShipDestructionHandlerInterface $handler) use (
32
                $destroyer,
33
                $destroyedShipWrapper,
34
                $cause,
35
                $informations
36
            ): void {
37
                $handler->handleShipDestruction(
38
                    $destroyer,
39
                    $destroyedShipWrapper,
40
                    $cause,
41
                    $informations
42
                );
43
            }
44
        );
45
    }
46
}
47