Passed
Push — master ( 288b46...98b0e3 )
by Nico
31:30 queued 08:00
created

PreFlightConditionsCheck::checkPreconditions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 20
ccs 14
cts 14
cp 1
crap 1
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib\Movement\Component\PreFlight;
6
7
use Stu\Module\Ship\Lib\Fleet\LeaveFleetInterface;
8
use Stu\Module\Ship\Lib\Movement\Component\PreFlight\Condition\PreFlightConditionInterface;
9
use Stu\Module\Ship\Lib\Movement\Route\FlightRouteInterface;
10
use Stu\Module\Ship\Lib\ShipWrapperInterface;
11
12
class PreFlightConditionsCheck implements PreFlightConditionsCheckInterface
13
{
14
    private LeaveFleetInterface $leaveFleet;
15
16
    /** @var array<string, PreFlightConditionInterface>  */
17
    private array $conditions;
18
19
    /**
20
     * @param array<string, PreFlightConditionInterface> $conditions
21
     */
22 2
    public function __construct(
23
        LeaveFleetInterface $leaveFleet,
24
        array $conditions
25
    ) {
26 2
        $this->leaveFleet = $leaveFleet;
27 2
        $this->conditions = $conditions;
28
    }
29
30 2
    public function checkPreconditions(
31
        array $wrappers,
32
        FlightRouteInterface $flightRoute,
33
        bool $isFixedFleetMode
34
    ): ConditionCheckResult {
35 2
        $conditionCheckResult = new ConditionCheckResult($this->leaveFleet, $isFixedFleetMode);
36
37 2
        array_walk(
38 2
            $this->conditions,
39 2
            fn (PreFlightConditionInterface $condition) => array_walk(
40 2
                $wrappers,
41 2
                fn (ShipWrapperInterface $wrapper) => $condition->check(
42 2
                    $wrapper,
43 2
                    $flightRoute,
44 2
                    $conditionCheckResult
45 2
                )
46 2
            )
47 2
        );
48
49 2
        return $conditionCheckResult;
50
    }
51
}
52