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

ShipAttackPreparation::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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