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

WebEmitterSystemData   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
c 0
b 0
f 0
dl 0
loc 60
ccs 0
cts 25
cp 0
rs 10
wmc 12

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getOwnedTholianWeb() 0 7 2
A getCooldown() 0 3 1
A __construct() 0 5 1
A getWebUnderConstruction() 0 6 2
A getSystemType() 0 3 1
A isUseable() 0 9 3
A setWebUnderConstructionId() 0 4 1
A setOwnedWebId() 0 4 1
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