Passed
Pull Request — master (#1930)
by Janko
14:58 queued 05:13
created

StateIconAndTitle   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Test Coverage

Coverage 71.7%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 49
dl 0
loc 83
ccs 38
cts 53
cp 0.717
rs 10
c 1
b 0
f 0
wmc 16

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
C getStateIconAndTitle() 0 73 15
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_RETROFIT) {
31
            return ['buttons/konstr1', 'Schiff wird umgerüstet'];
32
        }
33
34 7
        if ($state === ShipStateEnum::SHIP_STATE_REPAIR_ACTIVE) {
35 2
            $isBase = $ship->isBase();
36 2
            return ['buttons/rep2', sprintf('%s repariert die Station', $isBase ? 'Stationscrew' : 'Schiffscrew')];
37
        }
38
39 5
        if ($state === ShipStateEnum::SHIP_STATE_REPAIR_PASSIVE) {
40 2
            $isBase = $ship->isBase();
41 2
            $repairDuration = $wrapper->getRepairDuration();
42 2
            return ['buttons/rep2', sprintf('%s wird repariert (noch %d Runden)', $isBase ? 'Station' : 'Schiff', $repairDuration)];
43
        }
44
45 3
        $currentTurn = $this->game->getCurrentRound()->getTurn();
46 3
        $astroLab = $wrapper->getAstroLaboratorySystemData();
47
        if (
48 3
            $state === ShipStateEnum::SHIP_STATE_ASTRO_FINALIZING
49 3
            && $astroLab !== null
50
        ) {
51 1
            return ['buttons/map1', sprintf(
52 1
                'Schiff kartographiert (noch %d Runden)',
53 1
                $astroLab->getAstroStartTurn() + AstronomicalMappingEnum::TURNS_TO_FINISH - $currentTurn
54 1
            )];
55
        }
56
57 2
        $takeover = $ship->getTakeoverActive();
58
        if (
59 2
            $state === ShipStateEnum::SHIP_STATE_ACTIVE_TAKEOVER
60 2
            && $takeover !== null
61
        ) {
62 1
            $targetNamePlainText = $this->bbCodeParser->parse($takeover->getTargetShip()->getName())->getAsText();
63 1
            return ['buttons/take2', sprintf(
64 1
                'Schiff übernimmt die "%s" (noch %d Runden)',
65 1
                $targetNamePlainText,
66 1
                $wrapper->getTakeoverTicksLeft($takeover)
67 1
            )];
68
        }
69
70 1
        $takeover = $ship->getTakeoverPassive();
71 1
        if ($takeover !== null) {
72 1
            $sourceUserNamePlainText = $this->bbCodeParser->parse($takeover->getSourceShip()->getUser()->getName())->getAsText();
73 1
            return ['buttons/untake2', sprintf(
74 1
                'Schiff wird von Spieler "%s" übernommen (noch %d Runden)',
75 1
                $sourceUserNamePlainText,
76 1
                $wrapper->getTakeoverTicksLeft($takeover)
77 1
            )];
78
        }
79
80
        if ($state === ShipStateEnum::SHIP_STATE_GATHER_RESOURCES) {
81
            $miningqueue = $ship->getMiningQueue();
82
            $module = $ship->getShipSystem(ShipSystemTypeEnum::SYSTEM_BUSSARD_COLLECTOR)->getModule();
83
            $gathercount = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to $gathercount is dead and can be removed.
Loading history...
84
            if ($miningqueue !== null) {
85
                $locationmining = $miningqueue->getLocationMining();
86
                if ($module !== null) {
87
                    $gathercount = $module->getFactionId() == null ? 100 : 200;
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...
88
                    return [sprintf('commodities/%s', $locationmining->getCommodity()->getId()), sprintf(
89
                        'Schiff sammelt Ressourcen (~%d %s/Tick)',
90
                        $gathercount,
91
                        $locationmining->getCommodity()->getName()
92
                    )];
93
                }
94
            }
95
        }
96
97
        return null;
98
    }
99
}