Passed
Push — master ( 4ea0a9...ff5a87 )
by Janko
10:24
created

Fleet::getShipCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
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\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
use Doctrine\ORM\Mapping\Column;
10
use Doctrine\ORM\Mapping\Entity;
11
use Doctrine\ORM\Mapping\GeneratedValue;
12
use Doctrine\ORM\Mapping\Id;
13
use Doctrine\ORM\Mapping\Index;
14
use Doctrine\ORM\Mapping\JoinColumn;
15
use Doctrine\ORM\Mapping\ManyToOne;
16
use Doctrine\ORM\Mapping\OneToMany;
17
use Doctrine\ORM\Mapping\OneToOne;
18
use Doctrine\ORM\Mapping\OrderBy;
19
use Doctrine\ORM\Mapping\Table;
20
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...
21
use Stu\Orm\Repository\FleetRepository;
22
23
#[Table(name: 'stu_fleets')]
24
#[Index(name: 'fleet_user_idx', columns: ['user_id'])]
25
#[Entity(repositoryClass: FleetRepository::class)]
26
class Fleet implements FleetInterface
27
{
28
    #[Id]
29
    #[Column(type: 'integer')]
30
    #[GeneratedValue(strategy: 'IDENTITY')]
31
    private int $id;
32
33
    #[Column(type: 'string', length: 200)]
34
    private string $name = '';
35
36
    #[Column(type: 'integer')]
37
    private int $user_id = 0;
38
39
    #[Column(type: 'integer')]
40
    private int $ships_id = 0;
0 ignored issues
show
introduced by
The private property $ships_id is not used, and could be removed.
Loading history...
41
42
    #[Column(type: 'integer', nullable: true)]
43
    private ?int $defended_colony_id = null;
0 ignored issues
show
introduced by
The private property $defended_colony_id is not used, and could be removed.
Loading history...
44
45
    #[Column(type: 'integer', nullable: true)]
46
    private ?int $blocked_colony_id = null;
0 ignored issues
show
introduced by
The private property $blocked_colony_id is not used, and could be removed.
Loading history...
47
48
    #[Column(type: 'integer', nullable: true)]
49
    private ?int $sort = null;
50
51
    #[Column(type: 'boolean')]
52
    private bool $is_fixed = false;
53
54
    private string $hiddenStyle;
55
56
    #[ManyToOne(targetEntity: 'User')]
57
    #[JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
58
    private UserInterface $user;
59
60
    /**
61
     * @var ArrayCollection<int, ShipInterface>
62
     */
63
    #[OneToMany(targetEntity: 'Ship', mappedBy: 'fleet', indexBy: 'id')]
64
    #[OrderBy(['is_fleet_leader' => 'DESC', 'name' => 'ASC'])]
65
    private Collection $shiplist;
66
67
    #[OneToOne(targetEntity: 'Ship')]
68
    #[JoinColumn(name: 'ships_id', referencedColumnName: 'id')]
69
    private ShipInterface $fleetLeader;
70
71
    #[ManyToOne(targetEntity: 'Colony', inversedBy: 'defenders')]
72
    #[JoinColumn(name: 'defended_colony_id', referencedColumnName: 'id')]
73
    private ?ColonyInterface $defendedColony = null;
74
75
    #[ManyToOne(targetEntity: 'Colony', inversedBy: 'blockers')]
76
    #[JoinColumn(name: 'blocked_colony_id', referencedColumnName: 'id')]
77
    private ?ColonyInterface $blockedColony = null;
78
79
    public function __construct()
80
    {
81
        $this->shiplist = new ArrayCollection();
82
    }
83
84 8
    #[Override]
85
    public function getId(): int
86
    {
87 8
        return $this->id;
88
    }
89
90 7
    #[Override]
91
    public function getName(): string
92
    {
93 7
        return $this->name;
94
    }
95
96
    #[Override]
97
    public function setName(string $name): FleetInterface
98
    {
99
        $this->name = $name;
100
        return $this;
101
    }
102
103 1
    #[Override]
104
    public function getUserId(): int
105
    {
106 1
        return $this->user_id;
107
    }
108
109 4
    #[Override]
110
    public function getShips(): Collection
111
    {
112 4
        return $this->shiplist;
113
    }
114
115 2
    #[Override]
116
    public function getShipCount(): int
117
    {
118 2
        return $this->getShips()->count();
119
    }
120
121 1
    #[Override]
122
    public function getLeadShip(): ShipInterface
123
    {
124 1
        return $this->fleetLeader;
125
    }
126
127
    #[Override]
128
    public function setLeadShip(ShipInterface $ship): FleetInterface
129
    {
130
        $this->fleetLeader = $ship;
131
        return $this;
132
    }
133
134 2
    #[Override]
135
    public function getUser(): UserInterface
136
    {
137 2
        return $this->user;
138
    }
139
140
    #[Override]
141
    public function setUser(UserInterface $user): FleetInterface
142
    {
143
        $this->user = $user;
144
        return $this;
145
    }
146
147 2
    #[Override]
148
    public function getDefendedColony(): ?ColonyInterface
149
    {
150 2
        return $this->defendedColony;
151
    }
152
153
    #[Override]
154
    public function setDefendedColony(?ColonyInterface $defendedColony): FleetInterface
155
    {
156
        $this->defendedColony = $defendedColony;
157
        return $this;
158
    }
159
160 2
    #[Override]
161
    public function getBlockedColony(): ?ColonyInterface
162
    {
163 2
        return $this->blockedColony;
164
    }
165
166
    #[Override]
167
    public function setBlockedColony(?ColonyInterface $blockedColony): FleetInterface
168
    {
169
        $this->blockedColony = $blockedColony;
170
        return $this;
171
    }
172
173 1
    #[Override]
174
    public function getSort(): ?int
175
    {
176 1
        return $this->sort;
177
    }
178
179
    #[Override]
180
    public function setSort(?int $sort): FleetInterface
181
    {
182
        $this->sort = $sort;
183
184
        return $this;
185
    }
186
187
    #[Override]
188
    public function isFleetFixed(): bool
189
    {
190
        return $this->is_fixed;
191
    }
192
193
    #[Override]
194
    public function setIsFleetFixed(bool $isFixed): FleetInterface
195
    {
196
        $this->is_fixed = $isFixed;
197
        return $this;
198
    }
199
200 2
    #[Override]
201
    public function getCrewSum(): int
202
    {
203 2
        return array_reduce(
204 2
            $this->shiplist->toArray(),
205 2
            fn (int $sum, ShipInterface $ship): int => $sum + ($ship->isDestroyed() ? 0 : $ship->getBuildplan()->getCrew()),
206 2
            0
207 2
        );
208
    }
209
210 2
    #[Override]
211
    public function getHiddenStyle(): string
212
    {
213 2
        return $this->hiddenStyle;
214
    }
215
216 2
    #[Override]
217
    public function setHiddenStyle(string $hiddenStyle): FleetInterface
218
    {
219 2
        $this->hiddenStyle = $hiddenStyle;
220 2
        return $this;
221
    }
222
223
    #[Override]
224
    public function __toString(): string
225
    {
226
        return $this->getName();
227
    }
228
}
229