Passed
Pull Request — master (#1910)
by Nico
50:29 queued 24:38
created

ShipBuildplan::getModules()   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 0
dl 0
loc 4
ccs 0
cts 2
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\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\JoinColumn;
14
use Doctrine\ORM\Mapping\ManyToOne;
15
use Doctrine\ORM\Mapping\OneToMany;
16
use Doctrine\ORM\Mapping\Table;
17
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...
18
use Stu\Component\Ship\ShipModuleTypeEnum;
19
use Stu\Orm\Repository\ShipBuildplanRepository;
20
21
#[Table(name: 'stu_buildplans')]
22
#[Entity(repositoryClass: ShipBuildplanRepository::class)]
23
class ShipBuildplan implements ShipBuildplanInterface
24
{
25
    #[Id]
26
    #[Column(type: 'integer')]
27
    #[GeneratedValue(strategy: 'IDENTITY')]
28
    private int $id;
29
30
    #[Column(type: 'integer')]
31
    private int $rump_id = 0;
32
33
    #[Column(type: 'integer')]
34
    private int $user_id = 0;
35
36
    #[Column(type: 'string')]
37
    private string $name = '';
38
39
    #[Column(type: 'integer')]
40
    private int $buildtime = 0;
41
42
    #[Column(type: 'string', length: 32, nullable: true)]
43
    private ?string $signature = '';
44
45
    #[Column(type: 'smallint')]
46
    private int $crew = 0;
47
48
    /**
49
     * @var Collection<int, ShipInterface>
50
     */
51
    #[OneToMany(targetEntity: 'Ship', mappedBy: 'buildplan', fetch: 'EXTRA_LAZY')]
52
    private Collection $ships;
53
54
    #[ManyToOne(targetEntity: 'ShipRump')]
55
    #[JoinColumn(name: 'rump_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
56
    private ShipRumpInterface $shipRump;
57
58
    #[ManyToOne(targetEntity: 'User')]
59
    #[JoinColumn(name: 'user_id', referencedColumnName: 'id', onDelete: 'CASCADE')]
60
    private UserInterface $user;
61
62
    /**
63
     * @var Collection<int, BuildplanModuleInterface>
64
     */
65
    #[OneToMany(targetEntity: 'BuildplanModule', mappedBy: 'buildplan', indexBy: 'module_id', fetch: 'EXTRA_LAZY')]
66
    private Collection $modules;
67
68
    public function __construct()
69
    {
70
        $this->ships = new ArrayCollection();
71
        $this->modules = new ArrayCollection();
72
    }
73
74
    #[Override]
75
    public function getId(): int
76
    {
77
        return $this->id;
78
    }
79
80
    #[Override]
81
    public function getRumpId(): int
82
    {
83
        return $this->rump_id;
84
    }
85
86
    #[Override]
87
    public function setRumpId(int $shipRumpId): ShipBuildplanInterface
88
    {
89
        $this->rump_id = $shipRumpId;
90
91
        return $this;
92
    }
93
94
    #[Override]
95
    public function getUserId(): int
96
    {
97
        return $this->user_id;
98
    }
99
100
    #[Override]
101
    public function getUser(): UserInterface
102
    {
103
        return $this->user;
104
    }
105
106
    #[Override]
107
    public function setUser(UserInterface $user): ShipBuildplanInterface
108
    {
109
        $this->user = $user;
110
        return $this;
111
    }
112
113
    #[Override]
114
    public function getName(): string
115
    {
116
        return $this->name;
117
    }
118
119
    #[Override]
120
    public function setName(string $name): ShipBuildplanInterface
121
    {
122
        $this->name = $name;
123
124
        return $this;
125
    }
126
127
    #[Override]
128
    public function getBuildtime(): int
129
    {
130
        return $this->buildtime;
131
    }
132
133
    #[Override]
134
    public function setBuildtime(int $buildtime): ShipBuildplanInterface
135
    {
136
        $this->buildtime = $buildtime;
137
138
        return $this;
139
    }
140
141
    #[Override]
142
    public function getShipCount(): int
143
    {
144
        return $this->getShiplist()->count();
145
    }
146
147
    /**
148
     * @param array<int> $modules
149
     */
150
    public static function createBuildplanSignature(array $modules, int $crewUsage = 0): string
151
    {
152
        return md5(implode('_', $modules) . '_' . $crewUsage);
153
    }
154
155
    #[Override]
156
    public function getSignature(): ?string
157
    {
158
        return $this->signature;
159
    }
160
161
    #[Override]
162
    public function setSignature(?string $signature): ShipBuildplanInterface
163
    {
164
        $this->signature = $signature;
165
166
        return $this;
167
    }
168
169
    #[Override]
170
    public function getCrew(): int
171
    {
172
        return $this->crew;
173
    }
174
175
    #[Override]
176
    public function setCrew(int $crew): ShipBuildplanInterface
177
    {
178
        $this->crew = $crew;
179
180
        return $this;
181
    }
182
183
    #[Override]
184
    public function getShiplist(): Collection
185
    {
186
        return $this->ships;
187
    }
188
189
    #[Override]
190
    public function getRump(): ShipRumpInterface
191
    {
192
        return $this->shipRump;
193
    }
194
195
    #[Override]
196
    public function setRump(ShipRumpInterface $shipRump): ShipBuildplanInterface
197
    {
198
        $this->shipRump = $shipRump;
199
200
        return $this;
201
    }
202
203
    #[Override]
204
    public function getModulesByType(ShipModuleTypeEnum $type): array
205
    {
206
        return $this->getModules()
207
            ->filter(
208
                fn(BuildplanModuleInterface $buildplanModule): bool => $buildplanModule->getModuleType() === $type
209
            )
210
            ->toArray();
211
    }
212
213
    #[Override]
214
    public function getModules(): Collection
215
    {
216
        return $this->modules;
217
    }
218
}
219