Passed
Push — dev ( 12e9d6...f3475b )
by Nico
35:27
created

Location::getLocationMinings()   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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
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\DiscriminatorColumn;
11
use Doctrine\ORM\Mapping\DiscriminatorMap;
12
use Doctrine\ORM\Mapping\Entity;
13
use Doctrine\ORM\Mapping\GeneratedValue;
14
use Doctrine\ORM\Mapping\Id;
15
use Doctrine\ORM\Mapping\Index;
16
use Doctrine\ORM\Mapping\InheritanceType;
17
use Doctrine\ORM\Mapping\JoinColumn;
18
use Doctrine\ORM\Mapping\ManyToOne;
19
use Doctrine\ORM\Mapping\OneToMany;
20
use Doctrine\ORM\Mapping\OrderBy;
21
use Doctrine\ORM\Mapping\Table;
22
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...
23
use Stu\Component\Anomaly\Type\AnomalyTypeEnum;
24
use Stu\Orm\Repository\LocationRepository;
25
26
#[Table(name: 'stu_location')]
27
#[Index(name: 'location_coords_idx', columns: ['layer_id', 'cx', 'cy'])]
28
#[Index(name: 'location_coords_reverse_idx', columns: ['layer_id', 'cy', 'cx'])]
29
#[Index(name: 'location_field_type_idx', columns: ['field_id'])]
30
#[Entity(repositoryClass: LocationRepository::class)]
31
#[InheritanceType('JOINED')]
32
#[DiscriminatorColumn(name: 'discr', type: 'string')]
33
#[DiscriminatorMap(['map' => Map::class, 'systemMap' => StarSystemMap::class])]
34
abstract class Location implements LocationInterface
35
{
36
    #[Id]
37
    #[Column(type: 'integer')]
38
    #[GeneratedValue(strategy: 'IDENTITY')]
39
    private int $id;
40
41
    #[Column(type: 'integer', nullable: true)]
42
    private ?int $layer_id = null;
0 ignored issues
show
introduced by
The private property $layer_id is not used, and could be removed.
Loading history...
43
44
    #[Column(type: 'integer', nullable: true)]
45
    private ?int $cx = null;
46
47
    #[Column(type: 'integer', nullable: true)]
48
    private ?int $cy = null;
49
50
    #[Column(type: 'integer')]
51
    private int $field_id = 0;
52
53
    #[ManyToOne(targetEntity: 'Layer')]
54
    #[JoinColumn(name: 'layer_id', referencedColumnName: 'id')]
55
    protected ?LayerInterface $layer;
56
57
    #[ManyToOne(targetEntity: 'MapFieldType')]
58
    #[JoinColumn(name: 'field_id', referencedColumnName: 'id')]
59
    private MapFieldTypeInterface $mapFieldType;
60
61
    /**
62
     * @var ArrayCollection<int, ShipInterface>
63
     */
64
    #[OneToMany(targetEntity: 'Ship', mappedBy: 'location', fetch: 'EXTRA_LAZY')]
65
    private Collection $ships;
66
67
    /**
68
     * @var ArrayCollection<int, FlightSignatureInterface>
69
     */
70
    #[OneToMany(targetEntity: 'FlightSignature', mappedBy: 'location')]
71
    #[OrderBy(['time' => 'DESC'])]
72
    private Collection $signatures;
73
74
    /**
75
     * @var ArrayCollection<int, BuoyInterface>
76
     */
77
    #[OneToMany(targetEntity: 'Buoy', mappedBy: 'location')]
78
    private Collection $buoys;
79
80
    /**
81
     * @var ArrayCollection<int, AnomalyInterface>
82
     */
83
    #[OneToMany(targetEntity: 'Anomaly', mappedBy: 'location', fetch: 'EXTRA_LAZY')]
84
    private Collection $anomalies;
85
86
    /**
87
     * @var ArrayCollection<int, LocationMiningInterface>
88
     */
89
    #[OneToMany(targetEntity: 'LocationMining', mappedBy: 'location')]
90
    private Collection $locationMinings;
91
92
    public function __construct()
93
    {
94
        $this->ships = new ArrayCollection();
95
        $this->signatures = new ArrayCollection();
96
        $this->buoys = new ArrayCollection();
97
        $this->anomalies = new ArrayCollection();
98
    }
99
100
    #[Override]
101
    public function getId(): int
102
    {
103
        return $this->id;
104
    }
105
106
    #[Override]
107
    public function getCx(): ?int
108
    {
109
        return $this->cx;
110
    }
111
112
    #[Override]
113
    public function getCy(): ?int
114
    {
115
        return $this->cy;
116
    }
117
118
    #[Override]
119
    public function getFieldId(): int
120
    {
121
        return $this->field_id;
122
    }
123
124
    #[Override]
125
    public function getFieldType(): MapFieldTypeInterface
126
    {
127
        return $this->mapFieldType;
128
    }
129
130
    #[Override]
131
    public function setFieldType(MapFieldTypeInterface $mapFieldType): LocationInterface
132
    {
133
        $this->mapFieldType = $mapFieldType;
134
135
        return $this;
136
    }
137
138
    #[Override]
139
    public function getShips(): Collection
140
    {
141
        return $this->ships;
142
    }
143
144
    #[Override]
145
    public function getBuoys(): Collection
146
    {
147
        return $this->buoys;
148
    }
149
150
    #[Override]
151
    public function getAnomalies(bool $onlyActive = true): Collection
152
    {
153
        return $this->anomalies
154
            ->filter(fn(AnomalyInterface $anomaly): bool => !$onlyActive || $anomaly->isActive());
155
    }
156
157
    #[Override]
158
    public function hasAnomaly(AnomalyTypeEnum $type): bool
159
    {
160
        return $this->getAnomalies()
161
            ->exists(fn(int $key, AnomalyInterface $anomaly): bool => $anomaly->getAnomalyType()->getId() === $type->value);
162
    }
163
164
    #[Override]
165
    public function getSignatures(): Collection
166
    {
167
        return $this->signatures;
168
    }
169
170
    /**
171
     * @return Collection<int, WormholeEntryInterface>
172
     */
173
    protected abstract function getWormholeEntries(): Collection;
174
175
    #[Override]
176
    public function getRandomWormholeEntry(): ?WormholeEntryInterface
177
    {
178
        $wormholeEntries = $this->getWormholeEntries();
179
        if ($wormholeEntries->isEmpty()) {
180
            return null;
181
        }
182
183
        $usableEntries = $wormholeEntries
184
            ->filter(fn(WormholeEntryInterface $entry): bool => $entry->isUsable($this))
185
            ->toArray();
186
187
        return $usableEntries === [] ? null : $usableEntries[array_rand($usableEntries)];
188
    }
189
190
    #[Override]
191
    public function isMap(): bool
192
    {
193
        return $this instanceof MapInterface;
194
    }
195
196
    #[Override]
197
    public function isOverWormhole(): bool
198
    {
199
        return $this->isMap() && $this->getRandomWormholeEntry() !== null;
200
    }
201
202
    #[Override]
203
    public function getLocationMinings(): Collection
204
    {
205
        return $this->locationMinings;
206
    }
207
}
208