Passed
Push — dev ( a2895b...0690be )
by Janko
18:58 queued 09:24
created

SpacecraftBuildplan::setName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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