Passed
Push — master ( 92a2e9...9d73f4 )
by Nico
41:55
created

StateIconAndTitle::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
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\Ui;
6
7
use JBBCode\Parser;
8
use Stu\Component\Ship\AstronomicalMappingEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Ship\AstronomicalMappingEnum was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Stu\Component\Ship\ShipStateEnum;
10
use Stu\Component\Ship\System\ShipSystemTypeEnum;
11
use Stu\Module\Control\GameControllerInterface;
12
use Stu\Module\Ship\Lib\ShipWrapperInterface;
13
14
15
class StateIconAndTitle
16
{
17 8
    public function __construct(
18
        private GameControllerInterface $game,
19
        private Parser $bbCodeParser
20 8
    ) {}
21
22
    /**
23
     * @return array<string>|null
24
     */
25 7
    public function getStateIconAndTitle(ShipWrapperInterface $wrapper): ?array
26
    {
27 7
        $ship = $wrapper->get();
28 7
        $state = $ship->getState();
29
30 7
        if ($state === ShipStateEnum::SHIP_STATE_REPAIR_ACTIVE) {
31 2
            $isBase = $ship->isBase();
32 2
            return ['buttons/rep2', sprintf('%s repariert die Station', $isBase ? 'Stationscrew' : 'Schiffscrew')];
33
        }
34
35 5
        if ($state === ShipStateEnum::SHIP_STATE_REPAIR_PASSIVE) {
36 2
            $isBase = $ship->isBase();
37 2
            $repairDuration = $wrapper->getRepairDuration();
38 2
            return ['buttons/rep2', sprintf('%s wird repariert (noch %d Runden)', $isBase ? 'Station' : 'Schiff', $repairDuration)];
39
        }
40
41 3
        $currentTurn = $this->game->getCurrentRound()->getTurn();
42 3
        $astroLab = $wrapper->getAstroLaboratorySystemData();
43
        if (
44 3
            $state === ShipStateEnum::SHIP_STATE_ASTRO_FINALIZING
45 3
            && $astroLab !== null
46
        ) {
47 1
            return ['buttons/map1', sprintf(
48 1
                'Schiff kartographiert (noch %d Runden)',
49 1
                $astroLab->getAstroStartTurn() + AstronomicalMappingEnum::TURNS_TO_FINISH - $currentTurn
50 1
            )];
51
        }
52
53 2
        $takeover = $ship->getTakeoverActive();
54
        if (
55 2
            $state === ShipStateEnum::SHIP_STATE_ACTIVE_TAKEOVER
56 2
            && $takeover !== null
57
        ) {
58 1
            $targetNamePlainText = $this->bbCodeParser->parse($takeover->getTargetShip()->getName())->getAsText();
59 1
            return ['buttons/take2', sprintf(
60 1
                'Schiff übernimmt die "%s" (noch %d Runden)',
61 1
                $targetNamePlainText,
62 1
                $wrapper->getTakeoverTicksLeft($takeover)
63 1
            )];
64
        }
65
66 1
        $takeover = $ship->getTakeoverPassive();
67 1
        if ($takeover !== null) {
68 1
            $sourceUserNamePlainText = $this->bbCodeParser->parse($takeover->getSourceShip()->getUser()->getName())->getAsText();
69 1
            return ['buttons/untake2', sprintf(
70 1
                'Schiff wird von Spieler "%s" übernommen (noch %d Runden)',
71 1
                $sourceUserNamePlainText,
72 1
                $wrapper->getTakeoverTicksLeft($takeover)
73 1
            )];
74
        }
75
76
        if ($state === ShipStateEnum::SHIP_STATE_GATHER_RESOURCES) {
77
            $miningqueue = $ship->getMiningQueue();
78
            $module = $ship->getShipSystem(ShipSystemTypeEnum::SYSTEM_BUSSARD_COLLECTOR)->getModule();
79
            $gathercount = 0;
80
            if ($miningqueue) {
81
                $locationmining = $miningqueue->getLocationMining();
82
                if ($module) {
83
                    if ($module->getFactionId() == null) {
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $module->getFactionId() of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison === instead.
Loading history...
84
                        $gathercount =  100;
85
                    } else {
86
                        $gathercount = 200;
87
                    }
88
89
                    return [sprintf('commodities/%s', $locationmining->getCommodity()->getId()), sprintf(
90
                        'Schiff sammelt Ressourcen (~%d %s/Tick)',
91
                        $gathercount,
92
                        $locationmining->getCommodity()->getName()
93
                    )];
94
                }
95
            }
96
        }
97
98
        return null;
99
    }
100
}
101