Passed
Push — master ( fd2901...8c69d0 )
by Nico
10:36 queued 05:16
created

Ship::setColonyShipQueue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Entity;
6
7
use Doctrine\ORM\Mapping\Column;
8
use Doctrine\ORM\Mapping\Entity;
9
use Doctrine\ORM\Mapping\JoinColumn;
10
use Doctrine\ORM\Mapping\ManyToOne;
11
use Doctrine\ORM\Mapping\OneToOne;
12
use Doctrine\ORM\Mapping\Table;
13
use Stu\Component\Spacecraft\SpacecraftTypeEnum;
14
use Stu\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
15
use Stu\Component\Station\StationUtility;
16
use Stu\Lib\Transfer\TransferEntityTypeEnum;
17
use Stu\Orm\Repository\ShipRepository;
18
19
#[Table(name: 'stu_ship')]
20
#[Entity(repositoryClass: ShipRepository::class)]
21
class Ship extends Spacecraft
22
{
23
    #[Column(type: 'integer', nullable: true)]
24
    private ?int $fleet_id = null;
25
26
    #[Column(type: 'integer', nullable: true)]
27
    private ?int $docked_to_id = null;
0 ignored issues
show
introduced by
The private property $docked_to_id is not used, and could be removed.
Loading history...
28
29
    // used for sorting
30
    #[Column(type: 'boolean')]
31
    private bool $is_fleet_leader = false;
32
33
    #[ManyToOne(targetEntity: Fleet::class, inversedBy: 'ships')]
34
    #[JoinColumn(name: 'fleet_id', referencedColumnName: 'id')]
35
    private ?Fleet $fleet = null;
36
37
    #[ManyToOne(targetEntity: Station::class, inversedBy: 'dockedShips')]
38
    #[JoinColumn(name: 'docked_to_id', referencedColumnName: 'id')]
39
    private ?Station $dockedTo = null;
40
41
    #[OneToOne(targetEntity: Spacecraft::class, mappedBy: 'tractoredShip')]
42
    private ?Spacecraft $tractoringSpacecraft = null;
43
44
    #[OneToOne(targetEntity: MiningQueue::class, mappedBy: 'ship')]
45
    private ?MiningQueue $miningqueue = null;
46
47
    #[OneToOne(targetEntity: ColonyShipQueue::class, mappedBy: 'ship')]
48
    private ?ColonyShipQueue $colonyShipQueue = null;
49
50 22
    public function getType(): SpacecraftTypeEnum
51
    {
52 22
        return SpacecraftTypeEnum::SHIP;
53
    }
54
55 5
    public function getFleetId(): ?int
56
    {
57 5
        return $this->fleet_id;
58
    }
59
60
    public function setFleetId(?int $fleetId): Ship
61
    {
62
        $this->fleet_id = $fleetId;
63
        return $this;
64
    }
65
66 30
    public function getIsFleetLeader(): bool
67
    {
68 30
        return $this->getFleet() !== null && $this->is_fleet_leader;
69
    }
70
71 2
    public function setIsFleetLeader(bool $isFleetLeader): Ship
72
    {
73 2
        $this->is_fleet_leader = $isFleetLeader;
74 2
        return $this;
75
    }
76
77 38
    public function getFleet(): ?Fleet
78
    {
79 38
        return $this->fleet;
80
    }
81
82 2
    public function setFleet(?Fleet $fleet): Ship
83
    {
84 2
        $this->fleet = $fleet;
85 2
        return $this;
86
    }
87
88 30
    public function isFleetLeader(): bool
89
    {
90 30
        return $this->getIsFleetLeader();
91
    }
92
93 15
    public function isTractored(): bool
94
    {
95 15
        return $this->getTractoringSpacecraft() !== null;
96
    }
97
98 1
    public function dockedOnTradePost(): bool
99
    {
100 1
        $dockedTo = $this->getDockedTo();
101
102 1
        return $dockedTo !== null
103 1
            && $dockedTo->getTradePost() !== null;
104
    }
105
106 27
    public function getTractoringSpacecraft(): ?Spacecraft
107
    {
108 27
        return $this->tractoringSpacecraft;
109
    }
110
111
    public function setTractoringSpacecraft(?Spacecraft $spacecraft): Ship
112
    {
113
        $this->tractoringSpacecraft = $spacecraft;
114
        return $this;
115
    }
116
117 29
    public function getDockedTo(): ?Station
118
    {
119 29
        return $this->dockedTo;
120
    }
121
122 10
    public function setDockedTo(?Station $dockedTo): Ship
123
    {
124 10
        $currentDockedTo = $this->dockedTo;
125 10
        if($dockedTo === null && $currentDockedTo !== null) {
126 9
            $currentDockedTo->getDockedShips()->removeElement($this);
127
        }
128
129 10
        $this->dockedTo = $dockedTo;
130 10
        return $this;
131
    }
132
133 3
    public function canBuildConstruction(): bool
134
    {
135 3
        return StationUtility::canShipBuildConstruction($this);
136
    }
137
138 17
    public function isWarped(): bool
139
    {
140 17
        $tractoringShip = $this->getTractoringSpacecraft();
141
142 17
        if ($tractoringShip !== null) {
143
            return $tractoringShip->getWarpDriveState();
144
        }
145
146 17
        return parent::getWarpDriveState();
147
    }
148
149 7
    public function getAstroState(): bool
150
    {
151 7
        return $this->getSystemState(SpacecraftSystemTypeEnum::ASTRO_LABORATORY);
152
    }
153
154 1
    public function isBussardCollectorHealthy(): bool
155
    {
156 1
        return $this->isSystemHealthy(SpacecraftSystemTypeEnum::BUSSARD_COLLECTOR);
157
    }
158
159 1
    public function getMiningQueue(): ?MiningQueue
160
    {
161 1
        return $this->miningqueue;
162
    }
163
164
    public function getColonyShipQueue(): ?ColonyShipQueue
165
    {
166
        return $this->colonyShipQueue;
167
    }
168
169
    public function setColonyShipQueue(?ColonyShipQueue $queue): Ship
170
    {
171
        $this->colonyShipQueue = $queue;
172
        return $this;
173
    }
174
175 23
    public function getTransferEntityType(): TransferEntityTypeEnum
176
    {
177 23
        return TransferEntityTypeEnum::SHIP;
178
    }
179
}
180