Passed
Push — dev ( ca533f...46d61b )
by Janko
14:22
created

ColonySandbox::getUser()   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\OrderBy;
17
use Doctrine\ORM\Mapping\Table;
18
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...
19
use Stu\Component\Colony\ColonyMenuEnum;
20
use Stu\Lib\Colony\PlanetFieldHostInterface;
21
use Stu\Lib\Colony\PlanetFieldHostTypeEnum;
22
use Stu\Module\Colony\View\Sandbox\ShowColonySandbox;
0 ignored issues
show
Bug introduced by
The type Stu\Module\Colony\View\Sandbox\ShowColonySandbox 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\Orm\Repository\ColonySandboxRepository;
24
25
#[Table(name: 'stu_colony_sandbox')]
26
#[Entity(repositoryClass: ColonySandboxRepository::class)]
27
class ColonySandbox implements ColonySandboxInterface, PlanetFieldHostInterface
28
{
29
    #[Id]
30
    #[Column(type: 'integer')]
31
    #[GeneratedValue(strategy: 'IDENTITY')]
32
    private int $id;
33
34
    #[Column(type: 'integer')]
35
    private int $colony_id;
0 ignored issues
show
introduced by
The private property $colony_id is not used, and could be removed.
Loading history...
36
37
    #[Column(type: 'string')]
38
    private string $name = '';
39
40
    #[Column(type: 'integer', length: 5)]
41
    private int $bev_work = 0;
42
43
    #[Column(type: 'integer', length: 5)]
44
    private int $bev_max = 0;
45
46
    #[Column(type: 'integer', length: 5)]
47
    private int $max_eps = 0;
48
49
    #[Column(type: 'integer', length: 5)]
50
    private int $max_storage = 0;
51
52
    #[Column(type: 'text', nullable: true)]
53
    private ?string $mask = null;
54
55
    /**
56
     * @var ArrayCollection<int, PlanetFieldInterface>
57
     */
58
    #[OneToMany(targetEntity: 'PlanetField', mappedBy: 'sandbox', indexBy: 'field_id', fetch: 'EXTRA_LAZY')]
59
    #[OrderBy(['field_id' => 'ASC'])]
60
    private Collection $planetFields;
61
62
    #[ManyToOne(targetEntity: 'Colony')]
63
    #[JoinColumn(name: 'colony_id', referencedColumnName: 'id')]
64
    private ColonyInterface $colony;
65
66
    public function __construct()
67
    {
68
        $this->planetFields = new ArrayCollection();
69
    }
70
71
    #[Override]
72
    public function getId(): int
73
    {
74
        return $this->id;
75
    }
76
77
    #[Override]
78
    public function getUser(): UserInterface
79
    {
80
        return $this->getColony()->getUser();
81
    }
82
83
    #[Override]
84
    public function getColony(): ColonyInterface
85
    {
86
        return $this->colony;
87
    }
88
89
    #[Override]
90
    public function setColony(ColonyInterface $colony): ColonySandboxInterface
91
    {
92
        $this->colony = $colony;
93
94
        return $this;
95
    }
96
97
    #[Override]
98
    public function getName(): string
99
    {
100
        return $this->name;
101
    }
102
103
    #[Override]
104
    public function setName(string $name): ColonySandboxInterface
105
    {
106
        $this->name = $name;
107
        return $this;
108
    }
109
110
    #[Override]
111
    public function getWorkers(): int
112
    {
113
        return $this->bev_work;
114
    }
115
116
    #[Override]
117
    public function setWorkers(int $bev_work): ColonySandboxInterface
118
    {
119
        $this->bev_work = $bev_work;
120
        return $this;
121
    }
122
123
    #[Override]
124
    public function getMaxBev(): int
125
    {
126
        return $this->bev_max;
127
    }
128
129
    #[Override]
130
    public function setMaxBev(int $bev_max): ColonySandboxInterface
131
    {
132
        $this->bev_max = $bev_max;
133
        return $this;
134
    }
135
136
    #[Override]
137
    public function getPopulation(): int
138
    {
139
        return $this->getMaxBev();
140
    }
141
142
    #[Override]
143
    public function getMaxEps(): int
144
    {
145
        return $this->max_eps;
146
    }
147
148
    #[Override]
149
    public function setMaxEps(int $max_eps): ColonySandboxInterface
150
    {
151
        $this->max_eps = $max_eps;
152
        return $this;
153
    }
154
155
    #[Override]
156
    public function getMaxStorage(): int
157
    {
158
        return $this->max_storage;
159
    }
160
161
    #[Override]
162
    public function setMaxStorage(int $max_storage): ColonySandboxInterface
163
    {
164
        $this->max_storage = $max_storage;
165
        return $this;
166
    }
167
168
    #[Override]
169
    public function getMask(): ?string
170
    {
171
        return $this->mask;
172
    }
173
174
    #[Override]
175
    public function setMask(?string $mask): ColonySandboxInterface
176
    {
177
        $this->mask = $mask;
178
        return $this;
179
    }
180
181
    #[Override]
182
    public function getPlanetFields(): Collection
183
    {
184
        return $this->planetFields;
185
    }
186
187
    #[Override]
188
    public function getTwilightZone(int $timestamp): int
189
    {
190
        return $this->getColony()->getTwilightZone($timestamp);
191
    }
192
193
    #[Override]
194
    public function getSurfaceWidth(): int
195
    {
196
        return $this->getColony()->getSurfaceWidth();
197
    }
198
199
    #[Override]
200
    public function getColonyClass(): ColonyClassInterface
201
    {
202
        return $this->getColony()->getColonyClass();
203
    }
204
205
    #[Override]
206
    public function isColony(): bool
207
    {
208
        return false;
209
    }
210
211
    #[Override]
212
    public function getHostType(): PlanetFieldHostTypeEnum
213
    {
214
        return PlanetFieldHostTypeEnum::SANDBOX;
215
    }
216
217
    #[Override]
218
    public function getDefaultViewIdentifier(): string
219
    {
220
        return ShowColonySandbox::VIEW_IDENTIFIER;
221
    }
222
223
    #[Override]
224
    public function isMenuAllowed(ColonyMenuEnum $menu): bool
225
    {
226
        return in_array($menu, [
227
            ColonyMenuEnum::MENU_MAINSCREEN,
228
            ColonyMenuEnum::MENU_BUILD,
229
            ColonyMenuEnum::MENU_BUILDINGS,
230
            ColonyMenuEnum::MENU_INFO,
231
            ColonyMenuEnum::MENU_SOCIAL
232
        ]);
233
    }
234
235
    #[Override]
236
    public function getComponentParameters(): string
237
    {
238
        return sprintf(
239
            '&hosttype=%d&id=%d',
240
            $this->getHostType()->value,
241
            $this->getId()
242
        );
243
    }
244
}
245