Passed
Push — master ( f50aa1...d726cb )
by Nico
57:47 queued 28:23
created

ModuleFabricationListItem::getEnergyCost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
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\Repository\ModuleQueueRepositoryInterface;
11
12
final class ModuleFabricationListItem
13
{
14
    public function __construct(
15
        private ModuleQueueRepositoryInterface $moduleQueueRepository,
16
        private ModuleInterface $module,
17
        private ColonyInterface $colony
18
    ) {
19
    }
20
21
    public function getModule(): ModuleInterface
22
    {
23
        return $this->module;
24
    }
25
26
    public function getModuleId(): int
27
    {
28
        return $this->module->getId();
29
    }
30
31
    public function getCommodityId(): int
32
    {
33
        return $this->module->getCommodityId();
34
    }
35
36
    public function getName(): string
37
    {
38
        return $this->module->getName();
39
    }
40
41
    public function getEnergyCost(): int
42
    {
43
        return $this->module->getEcost();
44
    }
45
46
    /** @return array<int, ModuleCostInterface> */
47
    public function getConstructionCosts(): array
48
    {
49
        return $this->module->getCostSorted();
50
    }
51
52
    public function getAmountQueued(): int
53
    {
54
        return $this->moduleQueueRepository->getAmountByColonyAndModule(
55
            $this->colony->getId(),
56
            $this->module->getId()
57
        );
58
    }
59
60
    public function getAmountInStock(): int
61
    {
62
        $result = $this->colony->getStorage()[$this->getCommodityId()] ?? null;
63
64
        if ($result === null) {
65
            return 0;
66
        }
67
        return $result->getAmount();
68
    }
69
}
70