Passed
Branch master (9bcc45)
by Janko
41:23
created

ModuleFabricationListItem   A

Complexity

Total Complexity 17

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 94
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0
wmc 17

14 Methods

Rating   Name   Duplication   Size   Complexity  
A getCommodityId() 0 3 1
A getConstructionCosts() 0 3 1
A getModuleType() 0 3 1
A addRump() 0 4 2
A getName() 0 3 1
A __construct() 0 5 1
A getEnergyCost() 0 3 1
A addBuildplan() 0 4 2
A getModuleLevel() 0 3 1
A getAmountInStock() 0 8 2
A getAmountQueued() 0 5 1
A getClass() 0 8 1
A getModule() 0 3 1
A getModuleId() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Colony\View\ShowModuleFab;
6
7
use Stu\Orm\Entity\ColonyInterface;
8
use Stu\Orm\Entity\ModuleCostInterface;
9
use Stu\Orm\Entity\ModuleInterface;
10
use Stu\Orm\Entity\ShipBuildplanInterface;
11
use Stu\Orm\Entity\ShipRumpInterface;
12
use Stu\Orm\Repository\ModuleQueueRepositoryInterface;
13
14
final class ModuleFabricationListItem
15
{
16
    /** @var array<int> */
17
    private array $rump_ids = [];
18
    /** @var array<int> */
19
    private array $buildplan_ids = [];
20
21
    public function __construct(
22
        private ModuleQueueRepositoryInterface $moduleQueueRepository,
23
        private ModuleInterface $module,
24
        private ColonyInterface $colony
25
    ) {}
26
27
    public function getModule(): ModuleInterface
28
    {
29
        return $this->module;
30
    }
31
32
    public function getModuleId(): int
33
    {
34
        return $this->module->getId();
35
    }
36
37
    public function getModuleType(): int
38
    {
39
        return $this->module->getType()->value;
40
    }
41
42
    public function getModuleLevel(): int
43
    {
44
        return $this->module->getLevel();
45
    }
46
47
    public function getCommodityId(): int
48
    {
49
        return $this->module->getCommodityId();
50
    }
51
52
    public function getName(): string
53
    {
54
        return $this->module->getName();
55
    }
56
57
    public function getEnergyCost(): int
58
    {
59
        return $this->module->getEcost();
60
    }
61
62
    /** @return array<int, ModuleCostInterface> */
63
    public function getConstructionCosts(): array
64
    {
65
        return $this->module->getCostSorted();
66
    }
67
68
    public function getAmountQueued(): int
69
    {
70
        return $this->moduleQueueRepository->getAmountByColonyAndModule(
71
            $this->colony->getId(),
72
            $this->module->getId()
73
        );
74
    }
75
76
    public function getAmountInStock(): int
77
    {
78
        $result = $this->colony->getStorage()[$this->getCommodityId()] ?? null;
79
80
        if ($result === null) {
81
            return 0;
82
        }
83
        return $result->getAmount();
84
    }
85
86
    public function addRump(ShipRumpInterface $shipRump): void
87
    {
88
        if (!in_array($shipRump->getId(), $this->rump_ids)) {
89
            $this->rump_ids[] = $shipRump->getId();
90
        }
91
    }
92
93
    public function addBuildplan(ShipBuildplanInterface $buildplan): void
94
    {
95
        if (!in_array($buildplan->getId(), $this->buildplan_ids)) {
96
            $this->buildplan_ids[] = $buildplan->getId();
97
        }
98
    }
99
100
    public function getClass(): string
101
    {
102
        return sprintf(
103
            'type_%d level_%d rump_%s buildplan_%s',
104
            $this->getModuleType(),
105
            $this->getModuleLevel(),
106
            implode(' rump_', $this->rump_ids),
107
            implode(' buildplan_', $this->buildplan_ids)
108
        );
109
    }
110
}
111