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

ShipAttackPreparation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
dl 0
loc 30
ccs 18
cts 18
cp 1
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getReady() 0 22 4
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