Passed
Pull Request — master (#1830)
by Nico
30:56
created

WebEmitterSystemData::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
ccs 0
cts 5
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Ship\System\Data;
6
7
use Stu\Component\Ship\System\ShipSystemTypeEnum;
8
use Stu\Orm\Entity\TholianWebInterface;
9
use Stu\Orm\Repository\ShipSystemRepositoryInterface;
10
use Stu\Orm\Repository\TholianWebRepositoryInterface;
11
12
class WebEmitterSystemData extends AbstractSystemData
13
{
14
    public ?int $webUnderConstructionId = null;
15
    public ?int $ownedWebId = null;
16
17
    public function __construct(
18
        ShipSystemRepositoryInterface $shipSystemRepository,
19
        private TholianWebRepositoryInterface $tholianWebRepository
20
    ) {
21
        parent::__construct($shipSystemRepository);
22
    }
23
24
    function getSystemType(): ShipSystemTypeEnum
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
25
    {
26
        return ShipSystemTypeEnum::SYSTEM_THOLIAN_WEB;
27
    }
28
29
    public function getWebUnderConstruction(): ?TholianWebInterface
30
    {
31
        if ($this->webUnderConstructionId === null) {
32
            return null;
33
        }
34
        return $this->tholianWebRepository->find($this->webUnderConstructionId);
35
    }
36
37
    public function getOwnedTholianWeb(): ?TholianWebInterface
38
    {
39
        if ($this->ownedWebId === null) {
40
            return null;
41
        }
42
43
        return $this->tholianWebRepository->find($this->ownedWebId);
44
    }
45
46
    public function setWebUnderConstructionId(?int $webId): WebEmitterSystemData
47
    {
48
        $this->webUnderConstructionId = $webId;
49
        return $this;
50
    }
51
52
    public function setOwnedWebId(?int $webId): WebEmitterSystemData
53
    {
54
        $this->ownedWebId = $webId;
55
        return $this;
56
    }
57
58
    public function getCooldown(): ?int
59
    {
60
        return $this->ship->getShipSystem(ShipSystemTypeEnum::SYSTEM_THOLIAN_WEB)->getCooldown();
61
    }
62
63
    public function isUseable(): bool
64
    {
65
        if ($this->webUnderConstructionId !== null) {
66
            return false;
67
        }
68
69
        $cooldown = $this->getCooldown();
70
71
        return $cooldown === null ? true : $cooldown < time();
72
    }
73
}
74