Passed
Push — dev ( 98511f...00baf5 )
by Janko
15:17
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;
0 ignored issues
show
introduced by
The private property $systems_id is not used, and could be removed.
Loading history...
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 9
    #[Override]
86
    public function getLayer(): ?LayerInterface
87
    {
88 9
        if ($this->layer === null) {
89
            throw new RuntimeException('Layer of Map can not be null');
90
        }
91 9
        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 1
    #[Override]
113
    public function getSystemTypeId(): ?int
114
    {
115 1
        return $this->system_type_id;
116
    }
117
118
    #[Override]
119
    public function setSystemTypeId(?int $system_type_id): MapInterface
120
    {
121
        $this->system_type_id = $system_type_id;
122
        return $this;
123
    }
124
125 1
    #[Override]
126
    public function getInfluenceAreaId(): ?int
127
    {
128 1
        return $this->influence_area_id;
129
    }
130
131
    #[Override]
132
    public function setInfluenceAreaId(?int $influenceAreaId): MapInterface
133
    {
134
        $this->influence_area_id = $influenceAreaId;
135
        return $this;
136
    }
137
138
    #[Override]
139
    public function getBordertypeId(): ?int
140
    {
141
        return $this->bordertype_id;
142
    }
143
144
    #[Override]
145
    public function setBordertypeId(?int $bordertype_id): MapInterface
146
    {
147
        $this->bordertype_id = $bordertype_id;
148
        return $this;
149
    }
150
151 1
    #[Override]
152
    public function getRegionId(): ?int
153
    {
154 1
        return $this->region_id;
155
    }
156
157
    #[Override]
158
    public function setRegionId(?int $region_id): MapInterface
159
    {
160
        $this->region_id = $region_id;
161
        return $this;
162
    }
163
164 1
    #[Override]
165
    public function getAdminRegionId(): ?int
166
    {
167 1
        return $this->admin_region_id;
168
    }
169
170
    #[Override]
171
    public function setAdminRegionId(?int $admin_region_id): MapInterface
172
    {
173
        $this->admin_region_id = $admin_region_id;
174
        return $this;
175
    }
176
177 2
    #[Override]
178
    public function getSystem(): ?StarSystemInterface
179
    {
180 2
        return $this->starSystem;
181
    }
182
183
    #[Override]
184
    public function setSystem(StarSystemInterface $starSystem): MapInterface
185
    {
186
        $this->starSystem = $starSystem;
187
        return $this;
188
    }
189
190 2
    #[Override]
191
    public function getInfluenceArea(): ?StarSystemInterface
192
    {
193 2
        return $this->influenceArea;
194
    }
195
196
    #[Override]
197
    public function setInfluenceArea(?StarSystemInterface $influenceArea): MapInterface
198
    {
199
        $this->influenceArea = $influenceArea;
200
        return $this;
201
    }
202
203
    #[Override]
204
    public function getStarSystemType(): ?StarSystemTypeInterface
205
    {
206
        return $this->starSystemType;
207
    }
208
209 1
    #[Override]
210
    public function getMapBorderType(): ?MapBorderTypeInterface
211
    {
212 1
        return $this->mapBorderType;
213
    }
214
215 3
    #[Override]
216
    public function getMapRegion(): ?MapRegionInterface
217
    {
218 3
        return $this->mapRegion;
219
    }
220
221 3
    #[Override]
222
    public function getAdministratedRegion(): ?MapRegionInterface
223
    {
224 3
        return $this->administratedRegion;
225
    }
226
227
    public function getBorder(): string
228
    {
229
        $borderType = $this->getMapBorderType();
230
        if ($borderType === null) {
231
            return '';
232
        }
233
        return 'border: 1px solid ' . $borderType->getColor();
234
    }
235
236 1
    public function getBorderColor(): string
237
    {
238 1
        $borderType = $this->getMapBorderType();
239 1
        if ($borderType === null) {
240 1
            return '';
241
        }
242
        return $borderType->getColor();
243
    }
244
245 2
    #[Override]
246
    protected function getWormholeEntries(): Collection
247
    {
248 2
        return $this->wormholeEntries;
249
    }
250
251 1
    #[Override]
252
    public function getSectorId(): ?int
253
    {
254 1
        $layer = $this->getLayer();
255 1
        if ($layer === null) {
256
            throw new RuntimeException('Layer of Map can not be null');
257
        }
258
259 1
        $cx = $this->getCx();
260 1
        $cy = $this->getCy();
261 1
        if ($cx === null || $cy === null) {
262
            throw new RuntimeException('Cx and Cy of Map can not be null');
263
        }
264
265 1
        return $layer->getSectorId(
266 1
            (int) ceil($cx / MapEnum::FIELDS_PER_SECTION),
267 1
            (int) ceil($cy / MapEnum::FIELDS_PER_SECTION)
268 1
        );
269
    }
270
271 7
    #[Override]
272
    public function getSectorString(): string
273
    {
274 7
        return  $this->getCx() . '|' . $this->getCy();
275
    }
276
}
277