Passed
Push — master ( 0a21cd...0ad97c )
by Janko
05:01
created

WebEmitterSystemData::getWebUnderConstruction()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
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\TholianWeb;
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 8
    public function __construct(
20
        SpacecraftSystemRepositoryInterface $shipSystemRepository,
21
        private TholianWebRepositoryInterface $tholianWebRepository,
22
        StatusBarFactoryInterface $statusBarFactory
23
    ) {
24 8
        parent::__construct($shipSystemRepository, $statusBarFactory);
25
    }
26
27 5
    #[Override]
28
    public function getSystemType(): SpacecraftSystemTypeEnum
29
    {
30 5
        return SpacecraftSystemTypeEnum::THOLIAN_WEB;
31
    }
32
33 4
    public function getWebUnderConstruction(): ?TholianWeb
34
    {
35 4
        if ($this->webUnderConstructionId === null) {
36 4
            return null;
37
        }
38 2
        return $this->tholianWebRepository->find($this->webUnderConstructionId);
39
    }
40
41 5
    public function getOwnedTholianWeb(): ?TholianWeb
42
    {
43 5
        if ($this->ownedWebId === null) {
44 2
            return null;
45
        }
46
47 3
        return $this->tholianWebRepository->find($this->ownedWebId);
48
    }
49
50 3
    public function setWebUnderConstructionId(?int $webId): WebEmitterSystemData
51
    {
52 3
        $this->webUnderConstructionId = $webId;
53 3
        return $this;
54
    }
55
56 3
    public function setOwnedWebId(?int $webId): WebEmitterSystemData
57
    {
58 3
        $this->ownedWebId = $webId;
59 3
        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