Passed
Push — master ( fd4f11...882af9 )
by Nico
25:47
created

InitializeShowTransfer::init()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 13
c 0
b 0
f 0
nc 1
nop 5
dl 0
loc 25
ccs 0
cts 15
cp 0
crap 2
rs 9.8333
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Lib\Transfer;
6
7
use Stu\Component\Player\Relation\PlayerRelationDeterminatorInterface;
8
use Stu\Lib\Transfer\BeamUtilInterface;
9
use Stu\Lib\Transfer\Strategy\TransferStrategyProviderInterface;
10
use Stu\Lib\Transfer\TransferInformation;
11
use Stu\Lib\Transfer\TransferTypeEnum;
12
use Stu\Module\Control\GameControllerInterface;
13
use Stu\Orm\Entity\ColonyInterface;
14
use Stu\Orm\Entity\ShipInterface;
15
16
final class InitializeShowTransfer implements InitializeShowTransferInterface
17
{
18
19
    public function __construct(
20
        private BeamUtilInterface $beamUtil,
21
        private PlayerRelationDeterminatorInterface $playerRelationDeterminator,
22
        private TransferStrategyProviderInterface $transferStrategyProvider
23
    ) {}
24
25
    public function init(
26
        ColonyInterface|ShipInterface $from,
27
        ColonyInterface|ShipInterface $to,
28
        bool $isUnload,
29
        TransferTypeEnum $transferType,
30
        GameControllerInterface $game
31
    ): void {
32
        $user = $game->getUser();
33
34
        $transferInformation = new TransferInformation(
35
            $transferType,
36
            $from,
37
            $to,
38
            $isUnload,
39
            $this->playerRelationDeterminator->isFriend($to->getUser(), $from->getUser())
40
        );
41
42
        $this->setPageTitle($transferInformation, $game);
43
44
        $game->setTemplateVar('TARGET', $to);
45
        $game->setTemplateVar('OWNS_TARGET', $to->getUser() === $user);
46
        $game->setTemplateVar('TRANSFER_INFO', $transferInformation);
47
48
        $strategy = $this->transferStrategyProvider->getTransferStrategy($transferType);
49
        $strategy->setTemplateVariables($isUnload, $from, $to, $game);
50
    }
51
52
53
    private function setPageTitle(
54
        TransferInformation $transferInformation,
55
        GameControllerInterface $game
56
    ): void {
57
        $game->setPageTitle(sprintf(
58
            '%s %s %s %s',
59
            $transferInformation->getTransferType()->getGoodName(),
60
            $transferInformation->isUnload() ? 'zu' : 'von',
61
            $transferInformation->isColonyTarget() ? 'Kolonie' : 'Schiff',
62
            $this->beamUtil->isDockTransfer($transferInformation->getSource(), $transferInformation->getTarget()) ? 'transferieren' : 'beamen'
63
        ));
64
    }
65
}
66