Passed
Push — dev ( 216c8f...156d5c )
by Janko
15:03
created

User::getTutorials()   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\Entity;
11
use Doctrine\ORM\Mapping\GeneratedValue;
12
use Doctrine\ORM\Mapping\Id;
13
use Doctrine\ORM\Mapping\Index;
14
use Doctrine\ORM\Mapping\JoinColumn;
15
use Doctrine\ORM\Mapping\ManyToOne;
16
use Doctrine\ORM\Mapping\OneToMany;
17
use Doctrine\ORM\Mapping\OneToOne;
18
use Doctrine\ORM\Mapping\OrderBy;
19
use Doctrine\ORM\Mapping\Table;
20
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...
21
use Stu\Component\Game\GameEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Game\GameEnum 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...
22
use Stu\Component\Player\UserAwardEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Component\Player\UserAwardEnum 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\Module\PlayerSetting\Lib\UserEnum;
0 ignored issues
show
Bug introduced by
The type Stu\Module\PlayerSetting\Lib\UserEnum 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...
24
use Stu\Orm\Repository\UserRepository;
25
26
#[Table(name: 'stu_user')]
27
#[Index(name: 'user_alliance_idx', columns: ['allys_id'])]
28
#[Entity(repositoryClass: UserRepository::class)]
29
class User implements UserInterface
30
{
31
    #[Id]
32
    #[Column(type: 'integer')]
33
    #[GeneratedValue(strategy: 'IDENTITY')]
34
    private int $id;
35
36
    #[Column(type: 'string')]
37
    private string $username = '';
38
39
    #[Column(type: 'integer', nullable: true)]
40
    private ?int $allys_id = null;
41
42
    #[Column(type: 'integer')]
43
    private int $race = 9;
44
45
    #[Column(type: 'smallint')]
46
    private int $state = UserEnum::USER_STATE_NEW;
47
48
    #[Column(type: 'integer')]
49
    private int $lastaction = 0;
50
51
    #[Column(type: 'integer')]
52
    private int $kn_lez = 0;
53
54
    #[Column(type: 'boolean')]
55
    private bool $vac_active = false;
56
57
    #[Column(type: 'integer')]
58
    private int $vac_request_date = 0;
59
60
    #[Column(type: 'text')]
61
    private string $description = '';
62
63
    #[Column(type: 'text')]
64
    private string $sessiondata = '';
65
66
    #[Column(type: 'integer')]
67
    private int $prestige = 0;
68
69
    #[Column(type: 'boolean')]
70
    private bool $deals = false;
71
72
    #[Column(type: 'integer', nullable: true)]
73
    private ?int $last_boarding = null;
74
75
    #[OneToOne(targetEntity: 'UserRegistration', mappedBy: 'user', cascade: ['all'])]
76
    private UserRegistrationInterface $registration;
77
78
    #[ManyToOne(targetEntity: 'Alliance', inversedBy: 'members')]
79
    #[JoinColumn(name: 'allys_id', referencedColumnName: 'id')]
80
    private ?AllianceInterface $alliance = null;
81
82
    #[ManyToOne(targetEntity: 'Faction')]
83
    #[JoinColumn(name: 'race', referencedColumnName: 'id')]
84
    private FactionInterface $faction;
85
86
    /**
87
     * @var ArrayCollection<int, BuoyInterface>
88
     */
89
    #[OneToMany(targetEntity: 'Buoy', mappedBy: 'user')]
90
    private Collection $buoys;
91
92
    /**
93
     * @var ArrayCollection<int, UserAwardInterface>
94
     */
95
    #[OneToMany(targetEntity: 'UserAward', mappedBy: 'user', indexBy: 'award_id')]
96
    #[OrderBy(['award_id' => 'ASC'])]
97
    private Collection $awards;
98
99
    /**
100
     * @var ArrayCollection<int, ColonyInterface>
101
     */
102
    #[OneToMany(targetEntity: 'Colony', mappedBy: 'user', indexBy: 'id')]
103
    #[OrderBy(['colonies_classes_id' => 'ASC', 'id' => 'ASC'])]
104
    private Collection $colonies;
105
106
    /**
107
     * @var ArrayCollection<int, UserLayerInterface>
108
     */
109
    #[OneToMany(targetEntity: 'UserLayer', mappedBy: 'user', indexBy: 'layer_id')]
110
    private Collection $userLayers;
111
112
    #[OneToOne(targetEntity: 'UserLock', mappedBy: 'user')]
113
    private ?UserLockInterface $userLock = null;
114
115
    /**
116
     * @var ArrayCollection<string, UserSettingInterface>
117
     */
118
    #[OneToMany(targetEntity: 'UserSetting', mappedBy: 'user', indexBy: 'setting')]
119
    private Collection $settings;
120
121
    /**
122
     * @var ArrayCollection<int, UserCharacterInterface>
123
     */
124
    #[OneToMany(targetEntity: 'UserCharacter', mappedBy: 'user')]
125
    private Collection $characters;
126
127
    /**
128
     * @var ArrayCollection<int, ColonyScanInterface>
129
     */
130
    #[OneToMany(targetEntity: 'ColonyScan', mappedBy: 'user', indexBy: 'id', fetch: 'EXTRA_LAZY')]
131
    #[OrderBy(['colony_id' => 'ASC', 'date' => 'ASC'])]
132
    private Collection $colonyScans;
133
134
    #[OneToOne(targetEntity: 'PirateWrath', mappedBy: 'user')]
135
    private ?PirateWrathInterface $pirateWrath = null;
136
137
    /**
138
     * @var ArrayCollection<int, UserTutorialInterface>
139
     */
140
    #[OneToMany(targetEntity: 'UserTutorial', mappedBy: 'user', indexBy: 'tutorial_step_id', fetch: 'EXTRA_LAZY')]
141
    private Collection $tutorials;
142
143
    /** @var null|array<mixed> */
144
    private $sessiondataUnserialized;
145
146
    /**
147
     * @var ArrayCollection<int, WormholeRestriction>
148
     */
149
    #[OneToMany(targetEntity: 'WormholeRestriction', mappedBy: 'user')]
150
    private Collection $wormholeRestrictions;
151
152
    public function __construct()
153
    {
154
        $this->awards = new ArrayCollection();
155
        $this->colonies = new ArrayCollection();
156
        $this->userLayers = new ArrayCollection();
157
        $this->settings = new ArrayCollection();
158
        $this->characters = new ArrayCollection();
159
        $this->buoys = new ArrayCollection();
160
        $this->colonyScans = new ArrayCollection();
161
        $this->tutorials = new ArrayCollection();
162
        $this->wormholeRestrictions = new ArrayCollection();
163
    }
164
165 201
    #[Override]
166
    public function getId(): int
167
    {
168 201
        return $this->id;
169
    }
170
171 3
    #[Override]
172
    public function getRegistration(): UserRegistrationInterface
173
    {
174 3
        return $this->registration;
175
    }
176
177
    #[Override]
178
    public function setRegistration(UserRegistrationInterface $registration): UserInterface
179
    {
180
        $this->registration = $registration;
181
182
        return $this;
183
    }
184
185 201
    #[Override]
186
    public function getName(): string
187
    {
188
        //if UMODE active, add info to user name
189 201
        if ($this->isVacationRequestOldEnough()) {
190
            return $this->username . '[b][color=red] (UMODE)[/color][/b]';
191
        }
192 201
        return $this->username;
193
    }
194
195
    #[Override]
196
    public function setUsername(string $username): UserInterface
197
    {
198
        $this->username = $username;
199
        return $this;
200
    }
201
202 201
    #[Override]
203
    public function getFactionId(): int
204
    {
205 201
        return $this->race;
206
    }
207
208
    #[Override]
209
    public function setFaction(FactionInterface $faction): UserInterface
210
    {
211
        $this->faction = $faction;
212
        return $this;
213
    }
214
215 11
    #[Override]
216
    public function getFaction(): FactionInterface
217
    {
218 11
        return $this->faction;
219
    }
220
221 1
    #[Override]
222
    public function getAwards(): Collection
223
    {
224 1
        return $this->awards;
225
    }
226
227 12
    #[Override]
228
    public function getColonies(): Collection
229
    {
230 12
        return $this->colonies;
231
    }
232
233 2
    #[Override]
234
    public function hasColony(): bool
235
    {
236
        if (
237 2
            $this->getState() === UserEnum::USER_STATE_COLONIZATION_SHIP
238 2
            || $this->getState() === UserEnum::USER_STATE_UNCOLONIZED
239
        ) {
240
            return false;
241
        }
242
243 2
        return !$this->getColonies()->isEmpty();
244
    }
245
246 6
    #[Override]
247
    public function getState(): int
248
    {
249 6
        return $this->state;
250
    }
251
252 1
    #[Override]
253
    public function isLocked(): bool
254
    {
255 1
        return $this->getUserLock() !== null && $this->getUserLock()->getRemainingTicks() > 0;
256
    }
257
258 1
    #[Override]
259
    public function getUserStateDescription(): string
260
    {
261 1
        if ($this->isLocked()) {
262
            return _('GESPERRT');
263
        }
264 1
        return UserEnum::getUserStateDescription($this->getState());
265
    }
266
267
    #[Override]
268
    public function setState(int $state): UserInterface
269
    {
270
        $this->state = $state;
271
        return $this;
272
    }
273
274 4
    #[Override]
275
    public function getLastaction(): int
276
    {
277 4
        return $this->lastaction;
278
    }
279
280
    #[Override]
281
    public function setLastaction(int $lastaction): UserInterface
282
    {
283
        $this->lastaction = $lastaction;
284
        return $this;
285
    }
286
287 4
    #[Override]
288
    public function getKnMark(): int
289
    {
290 4
        return $this->kn_lez;
291
    }
292
293
    #[Override]
294
    public function setKnMark(int $knMark): UserInterface
295
    {
296
        $this->kn_lez = $knMark;
297
        return $this;
298
    }
299
300 201
    #[Override]
301
    public function isVacationMode(): bool
302
    {
303 201
        return $this->vac_active;
304
    }
305
306
    #[Override]
307
    public function setVacationMode(bool $vacationMode): UserInterface
308
    {
309
        $this->vac_active = $vacationMode;
310
        return $this;
311
    }
312
313
    #[Override]
314
    public function getVacationRequestDate(): int
315
    {
316
        return $this->vac_request_date;
317
    }
318
319
    #[Override]
320
    public function setVacationRequestDate(int $date): UserInterface
321
    {
322
        $this->vac_request_date = $date;
323
324
        return $this;
325
    }
326
327 201
    #[Override]
328
    public function isVacationRequestOldEnough(): bool
329
    {
330 201
        return $this->isVacationMode() && (time() - $this->getVacationRequestDate() > UserEnum::VACATION_DELAY_IN_SECONDS);
331
    }
332
333 2
    #[Override]
334
    public function getDescription(): string
335
    {
336 2
        return $this->description;
337
    }
338
339
    #[Override]
340
    public function setDescription(string $description): UserInterface
341
    {
342
        $this->description = $description;
343
        return $this;
344
    }
345
346 5
    #[Override]
347
    public function getUserLayers(): Collection
348
    {
349 5
        return $this->userLayers;
350
    }
351
352 4
    #[Override]
353
    public function hasSeen(int $layerId): bool
354
    {
355 4
        return $this->getUserLayers()->containsKey($layerId);
356
    }
357
358 4
    #[Override]
359
    public function hasExplored(int $layerId): bool
360
    {
361 4
        return $this->hasSeen($layerId) && $this->getUserLayers()->get($layerId)->isExplored();
362
    }
363
364 201
    #[Override]
365
    public function getSettings(): Collection
366
    {
367 201
        return $this->settings;
368
    }
369
370 1
    #[Override]
371
    public function getSessiondata(): string
372
    {
373 1
        return $this->sessiondata;
374
    }
375
376
    #[Override]
377
    public function setSessiondata(string $sessiondata): UserInterface
378
    {
379
        $this->sessiondata = $sessiondata;
380
        $this->sessiondataUnserialized = null;
381
        return $this;
382
    }
383
384 5
    #[Override]
385
    public function getPrestige(): int
386
    {
387 5
        return $this->prestige;
388
    }
389
390
    #[Override]
391
    public function setPrestige(int $prestige): UserInterface
392
    {
393
        $this->prestige = $prestige;
394
        return $this;
395
    }
396
397 3
    #[Override]
398
    public function getDeals(): bool
399
    {
400 3
        return $this->deals;
401
    }
402
403 1
    #[Override]
404
    public function setDeals(bool $deals): UserInterface
405
    {
406 1
        $this->deals = $deals;
407 1
        return $this;
408
    }
409
410
    #[Override]
411
    public function getLastBoarding(): ?int
412
    {
413
        return $this->last_boarding;
414
    }
415
416
    #[Override]
417
    public function setLastBoarding(int $lastBoarding): UserInterface
418
    {
419
        $this->last_boarding = $lastBoarding;
420
        return $this;
421
    }
422
423 2
    #[Override]
424
    public function isOnline(): bool
425
    {
426 2
        return !($this->getLastAction() < time() - GameEnum::USER_ONLINE_PERIOD);
427
    }
428
429 20
    #[Override]
430
    public function getAlliance(): ?AllianceInterface
431
    {
432 20
        return $this->alliance;
433
    }
434
435
    #[Override]
436
    public function setAlliance(?AllianceInterface $alliance): UserInterface
437
    {
438
        $this->alliance = $alliance;
439
        return $this;
440
    }
441
442
    #[Override]
443
    public function setAllianceId(?int $allianceId): UserInterface
444
    {
445
        $this->allys_id = $allianceId;
446
        return $this;
447
    }
448
449 3
    #[Override]
450
    public function getSessionDataUnserialized(): array
451
    {
452 3
        if ($this->sessiondataUnserialized === null) {
453 1
            $this->sessiondataUnserialized = unserialize($this->getSessionData());
454 1
            if (!is_array($this->sessiondataUnserialized)) {
455 1
                $this->sessiondataUnserialized = [];
456
            }
457
        }
458 3
        return $this->sessiondataUnserialized;
459
    }
460
461 1
    #[Override]
462
    public function isContactable(): bool
463
    {
464 1
        return $this->getId() != UserEnum::USER_NOONE;
465
    }
466
467 200
    #[Override]
468
    public function hasAward(int $awardId): bool
469
    {
470 200
        return $this->awards->containsKey($awardId) === true;
471
    }
472
473 4
    #[Override]
474
    public function hasStationsPmCategory(): bool
475
    {
476 4
        if ($this->isNpc()) {
477
            return true;
478
        }
479
480 4
        return $this->hasAward(UserAwardEnum::RESEARCHED_STATIONS);
481
    }
482
483 205
    public static function isUserNpc(int $userId): bool
484
    {
485 205
        return $userId < UserEnum::USER_FIRST_ID;
486
    }
487
488 201
    #[Override]
489
    public function isNpc(): bool
490
    {
491 201
        return self::isUserNpc($this->getId());
492
    }
493
494 1
    #[Override]
495
    public function getUserLock(): ?UserLockInterface
496
    {
497 1
        return $this->userLock;
498
    }
499
500
    #[Override]
501
    public function __toString(): string
502
    {
503
        return sprintf('userName: %s', $this->getName());
504
    }
505
506
    #[Override]
507
    public function hasTranslation(): bool
508
    {
509
        $text = $this->getDescription();
510
        return strpos($text, '[translate]') !== false && strpos($text, '[/translate]') !== false;
511
    }
512
513 1
    #[Override]
514
    public function getCharacters(): Collection
515
    {
516 1
        return $this->characters;
517
    }
518
519 1
    #[Override]
520
    public function getColonyScans(): Collection
521
    {
522 1
        return $this->colonyScans;
523
    }
524
525
    #[Override]
526
    public function getBuoys(): Collection
527
    {
528
        return $this->buoys;
529
    }
530
531 2
    #[Override]
532
    public function getPirateWrath(): ?PirateWrathInterface
533
    {
534 2
        return $this->pirateWrath;
535
    }
536
537
    #[Override]
538
    public function setPirateWrath(?PirateWrathInterface $wrath): UserInterface
539
    {
540
        $this->pirateWrath = $wrath;
541
542
        return $this;
543
    }
544
545
    #[Override]
546
    public function isProtectedAgainstPirates(): bool
547
    {
548
        $pirateWrath = $this->pirateWrath;
549
        if ($pirateWrath === null) {
550
            return false;
551
        }
552
553
        $timeout = $pirateWrath->getProtectionTimeout();
554
        if ($timeout === null) {
555
            return false;
556
        }
557
558
        return $timeout > time();
559
    }
560
561
    #[Override]
562
    public function getTutorials(): Collection
563
    {
564
        return $this->tutorials;
565
    }
566
567
    #[Override]
568
    public function getWormholeRestrictions(): Collection
569
    {
570
        return $this->wormholeRestrictions;
571
    }
572
}
573