Passed
Push — dev ( 2eb11f...3c2dab )
by Janko
09:11
created

WebEmitterSystemData::getOwnedTholianWeb()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Component\Spacecraft\System\Data;
6
7
use Override;
0 ignored issues
show
Bug introduced by
The type Override 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...
8
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
9
use Stu\Module\Template\StatusBarFactoryInterface;
10
use Stu\Orm\Entity\TholianWebInterface;
11
use Stu\Orm\Repository\SpacecraftSystemRepositoryInterface;
12
use Stu\Orm\Repository\TholianWebRepositoryInterface;
13
14
class WebEmitterSystemData extends AbstractSystemData
15
{
16
    public ?int $webUnderConstructionId = null;
17
    public ?int $ownedWebId = null;
18
19 1
    public function __construct(
20
        SpacecraftSystemRepositoryInterface $shipSystemRepository,
21
        private TholianWebRepositoryInterface $tholianWebRepository,
22
        StatusBarFactoryInterface $statusBarFactory
23
    ) {
24 1
        parent::__construct($shipSystemRepository, $statusBarFactory);
25
    }
26
27
    #[Override]
28
    public function getSystemType(): SpacecraftSystemTypeEnum
29
    {
30
        return SpacecraftSystemTypeEnum::THOLIAN_WEB;
31
    }
32
33 1
    public function getWebUnderConstruction(): ?TholianWebInterface
34
    {
35 1
        if ($this->webUnderConstructionId === null) {
36 1
            return null;
37
        }
38
        return $this->tholianWebRepository->find($this->webUnderConstructionId);
39
    }
40
41 1
    public function getOwnedTholianWeb(): ?TholianWebInterface
42
    {
43 1
        if ($this->ownedWebId === null) {
44 1
            return null;
45
        }
46
47
        return $this->tholianWebRepository->find($this->ownedWebId);
48
    }
49
50
    public function setWebUnderConstructionId(?int $webId): WebEmitterSystemData
51
    {
52
        $this->webUnderConstructionId = $webId;
53
        return $this;
54
    }
55
56
    public function setOwnedWebId(?int $webId): WebEmitterSystemData
57
    {
58
        $this->ownedWebId = $webId;
59
        return $this;
60
    }
61
62 1
    public function getCooldown(): ?int
63
    {
64 1
        return $this->spacecraft->getSpacecraftSystem(SpacecraftSystemTypeEnum::THOLIAN_WEB)->getCooldown();
65
    }
66
67 1
    public function isUseable(): bool
68
    {
69 1
        if ($this->webUnderConstructionId !== null) {
70
            return false;
71
        }
72
73 1
        $cooldown = $this->getCooldown();
74
75 1
        return $cooldown === null ? true : $cooldown < time();
76
    }
77
}
78