Passed
Pull Request — master (#2001)
by Nico
12:15
created

Map::getX()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
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\Index;
12
use Doctrine\ORM\Mapping\JoinColumn;
13
use Doctrine\ORM\Mapping\ManyToOne;
14
use Doctrine\ORM\Mapping\OneToMany;
15
use Doctrine\ORM\Mapping\OneToOne;
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 RuntimeException;
19
use Stu\Component\Map\MapEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Map\MapEnum 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\Orm\Repository\MapRepository;
21
22
#[Table(name: 'stu_map')]
23
#[Index(name: 'map_system_idx', columns: ['systems_id'])]
24
#[Index(name: 'map_system_type_idx', columns: ['system_type_id'])]
25
#[Index(name: 'map_influence_area_idx', columns: ['influence_area_id'])]
26
#[Index(name: 'map_bordertype_idx', columns: ['bordertype_id'])]
27
#[Index(name: 'map_admin_region_idx', columns: ['admin_region_id'])]
28
#[Entity(repositoryClass: MapRepository::class)]
29
class Map extends Location implements MapInterface
30
{
31
    #[Column(type: 'integer', nullable: true)]
32
    private ?int $system_type_id = null;
33
34
    #[Column(type: 'integer', nullable: true)]
35
    private ?int $systems_id = 0;
36
37
    #[Column(type: 'integer', nullable: true)]
38
    private ?int $influence_area_id = 0;
39
40
    #[Column(type: 'integer', nullable: true)]
41
    private ?int $bordertype_id = 0;
42
43
    #[Column(type: 'integer', nullable: true)]
44
    private ?int $region_id = 0;
45
46
    #[Column(type: 'integer', nullable: true)]
47
    private ?int $admin_region_id = null;
48
49
    #[OneToOne(targetEntity: 'StarSystem', inversedBy: 'map')]
50
    #[JoinColumn(name: 'systems_id', referencedColumnName: 'id')]
51
    private ?StarSystemInterface $starSystem = null;
52
53
    #[ManyToOne(targetEntity: 'StarSystem')]
54
    #[JoinColumn(name: 'influence_area_id', referencedColumnName: 'id')]
55
    private ?StarSystemInterface $influenceArea = null;
56
57
    #[ManyToOne(targetEntity: 'StarSystemType')]
58
    #[JoinColumn(name: 'system_type_id', referencedColumnName: 'id')]
59
    private ?StarSystemTypeInterface $starSystemType = null;
60
61
    #[ManyToOne(targetEntity: 'MapBorderType')]
62
    #[JoinColumn(name: 'bordertype_id', referencedColumnName: 'id')]
63
    private ?MapBorderTypeInterface $mapBorderType = null;
64
65
    #[ManyToOne(targetEntity: 'MapRegion')]
66
    #[JoinColumn(name: 'region_id', referencedColumnName: 'id')]
67
    private ?MapRegionInterface $mapRegion = null;
68
69
    #[ManyToOne(targetEntity: 'MapRegion')]
70
    #[JoinColumn(name: 'admin_region_id', referencedColumnName: 'id')]
71
    private ?MapRegionInterface $administratedRegion = null;
72
73
    /**
74
     * @var ArrayCollection<int, WormholeEntryInterface>
75
     */
76
    #[OneToMany(targetEntity: 'WormholeEntry', mappedBy: 'map')]
77
    private Collection $wormholeEntries;
78
79
    public function __construct()
80
    {
81
        parent::__construct();
82
        $this->wormholeEntries = new ArrayCollection();
83
    }
84
85 5
    #[Override]
86
    public function getLayer(): ?LayerInterface
87
    {
88 5
        if ($this->layer === null) {
89
            throw new RuntimeException('Layer of Map can not be null');
90
        }
91 5
        return $this->layer;
92
    }
93
94 2
    #[Override]
95
    public function getX(): int
96
    {
97 2
        if ($this->getCx() === null) {
98
            throw new RuntimeException('Cx of Map can not be null');
99
        }
100 2
        return $this->getCx();
101
    }
102
103 2
    #[Override]
104
    public function getY(): int
105
    {
106 2
        if ($this->getCy() === null) {
107
            throw new RuntimeException('Cy of Map can not be null');
108
        }
109 2
        return $this->getCy();
110
    }
111
112
    #[Override]
113
    public function getSystemsId(): ?int
114
    {
115
        return $this->systems_id;
116
    }
117
118
    #[Override]
119
    public function setSystemsId(?int $systems_id): MapInterface
120
    {
121
        $this->systems_id = $systems_id;
122
        return $this;
123
    }
124
125 1
    #[Override]
126
    public function getSystemTypeId(): ?int
127
    {
128 1
        return $this->system_type_id;
129
    }
130
131
    #[Override]
132
    public function setSystemTypeId(?int $system_type_id): MapInterface
133
    {
134
        $this->system_type_id = $system_type_id;
135
        return $this;
136
    }
137
138 1
    #[Override]
139
    public function getInfluenceAreaId(): ?int
140
    {
141 1
        return $this->influence_area_id;
142
    }
143
144
    #[Override]
145
    public function setInfluenceAreaId(?int $influenceAreaId): MapInterface
146
    {
147
        $this->influence_area_id = $influenceAreaId;
148
        return $this;
149
    }
150
151
    #[Override]
152
    public function getBordertypeId(): ?int
153
    {
154
        return $this->bordertype_id;
155
    }
156
157
    #[Override]
158
    public function setBordertypeId(?int $bordertype_id): MapInterface
159
    {
160
        $this->bordertype_id = $bordertype_id;
161
        return $this;
162
    }
163
164 1
    #[Override]
165
    public function getRegionId(): ?int
166
    {
167 1
        return $this->region_id;
168
    }
169
170
    #[Override]
171
    public function setRegionId(?int $region_id): MapInterface
172
    {
173
        $this->region_id = $region_id;
174
        return $this;
175
    }
176
177 1
    #[Override]
178
    public function getAdminRegionId(): ?int
179
    {
180 1
        return $this->admin_region_id;
181
    }
182
183
    #[Override]
184
    public function setAdminRegionId(?int $admin_region_id): MapInterface
185
    {
186
        $this->admin_region_id = $admin_region_id;
187
        return $this;
188
    }
189
190 2
    #[Override]
191
    public function getSystem(): ?StarSystemInterface
192
    {
193 2
        return $this->starSystem;
194
    }
195
196
    #[Override]
197
    public function setSystem(StarSystemInterface $starSystem): MapInterface
198
    {
199
        $this->starSystem = $starSystem;
200
        return $this;
201
    }
202
203 2
    #[Override]
204
    public function getInfluenceArea(): ?StarSystemInterface
205
    {
206 2
        return $this->influenceArea;
207
    }
208
209
    #[Override]
210
    public function setInfluenceArea(?StarSystemInterface $influenceArea): MapInterface
211
    {
212
        $this->influenceArea = $influenceArea;
213
        return $this;
214
    }
215
216
    #[Override]
217
    public function getStarSystemType(): ?StarSystemTypeInterface
218
    {
219
        return $this->starSystemType;
220
    }
221
222
    #[Override]
223
    public function getMapBorderType(): ?MapBorderTypeInterface
224
    {
225
        return $this->mapBorderType;
226
    }
227
228 3
    #[Override]
229
    public function getMapRegion(): ?MapRegionInterface
230
    {
231 3
        return $this->mapRegion;
232
    }
233
234 3
    #[Override]
235
    public function getAdministratedRegion(): ?MapRegionInterface
236
    {
237 3
        return $this->administratedRegion;
238
    }
239
240
    public function getBorder(): string
241
    {
242
        $borderType = $this->getMapBorderType();
243
        if ($borderType === null) {
244
            return '';
245
        }
246
        return 'border: 1px solid ' . $borderType->getColor();
247
    }
248
249 2
    #[Override]
250
    protected function getWormholeEntries(): Collection
251
    {
252 2
        return $this->wormholeEntries;
253
    }
254
255 1
    #[Override]
256
    public function getSectorId(): ?int
257
    {
258 1
        $layer = $this->getLayer();
259 1
        if ($layer === null) {
260
            throw new RuntimeException('Layer of Map can not be null');
261
        }
262
263 1
        $cx = $this->getCx();
264 1
        $cy = $this->getCy();
265 1
        if ($cx === null || $cy === null) {
266
            throw new RuntimeException('Cx and Cy of Map can not be null');
267
        }
268
269 1
        return $layer->getSectorId(
270 1
            (int) ceil($cx / MapEnum::FIELDS_PER_SECTION),
271 1
            (int) ceil($cy / MapEnum::FIELDS_PER_SECTION)
272 1
        );
273
    }
274
275 7
    #[Override]
276
    public function getSectorString(): string
277
    {
278 7
        return  $this->getCx() . '|' . $this->getCy();
279
    }
280
}
281