Passed
Pull Request — master (#1819)
by Nico
52:14 queued 25:19
created

ShipAttackPreparation::getReady()   A

Complexity

Conditions 4
Paths 6

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
nc 6
nop 4
dl 0
loc 22
ccs 16
cts 16
cp 1
crap 4
rs 9.8333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Ship\Lib\Battle;
6
7
use Stu\Module\Ship\Lib\Battle\Party\BattlePartyInterface;
8
use Stu\Module\Ship\Lib\Message\Message;
9
use Stu\Module\Ship\Lib\Message\MessageCollectionInterface;
10
11
final class ShipAttackPreparation implements ShipAttackPreparationInterface
12
{
13
14 2
    public function __construct(
15
        private FightLibInterface $fightLib
16
    ) {
17 2
    }
18
19 2
    public function getReady(
20
        BattlePartyInterface $attackers,
21
        BattlePartyInterface $defenders,
22
        bool $isOneWay,
23
        MessageCollectionInterface $messages
24
    ): void {
25 2
        foreach ($attackers->getActiveMembers() as $attacker) {
26 2
            $message = new Message(
27 2
                $attacker->get()->getUser()->getId(),
28 2
                null,
29 2
                $this->fightLib->ready($attacker)->getInformations()
30 2
            );
31 2
            $messages->add($message);
32
        }
33 2
        if (!$isOneWay) {
34 1
            foreach ($defenders->getActiveMembers() as $defender) {
35 1
                $message = new Message(
36 1
                    $defender->get()->getUser()->getId(),
37 1
                    null,
38 1
                    $this->fightLib->ready($defender)->getInformations()
39 1
                );
40 1
                $messages->add($message);
41
            }
42
        }
43
    }
44
}
45