Passed
Pull Request — master (#1904)
by Nico
39:29 queued 12:01
created

AstroEntryRepository::getByUser()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Orm\Repository;
6
7
use Doctrine\ORM\EntityRepository;
8
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...
9
use Stu\Orm\Entity\AstronomicalEntry;
10
use Stu\Orm\Entity\AstronomicalEntryInterface;
11
use Stu\Orm\Entity\ShipInterface;
12
use Stu\Orm\Entity\UserInterface;
13
14
/**
15
 * @extends EntityRepository<AstronomicalEntry>
16
 */
17
final class AstroEntryRepository extends EntityRepository implements AstroEntryRepositoryInterface
18
{
19
    #[Override]
20
    public function prototype(): AstronomicalEntryInterface
21
    {
22
        return new AstronomicalEntry();
23
    }
24
25
    #[Override]
26
    public function getByShipLocation(ShipInterface $ship, bool $showOverSystem = true): ?AstronomicalEntryInterface
27
    {
28
        $system = $ship->getSystem();
29
        if ($system === null && $showOverSystem) {
30
            $system = $ship->isOverSystem();
31
        }
32
        $mapRegion = $system === null ? $ship->getMapRegion() : null;
33
34
        return $this->findOneBy(
35
            [
36
                'user_id' => $ship->getUser()->getId(),
37
                'systems_id' => $system === null ? null : $system->getId(),
38
                'region_id' => $mapRegion === null ? null : $mapRegion->getId()
39
            ]
40
        );
41
    }
42
43
    #[Override]
44
    public function save(AstronomicalEntryInterface $entry): void
45
    {
46
        $em = $this->getEntityManager();
47
48
        $em->persist($entry);
49
    }
50
51
    #[Override]
52
    public function delete(AstronomicalEntryInterface $entry): void
53
    {
54
        $em = $this->getEntityManager();
55
56
        $em->remove($entry);
57
        $em->flush();
58
    }
59
60
61
    #[Override]
62
    public function truncateAllAstroEntries(): void
63
    {
64
        $this->getEntityManager()->createQuery(
65
            sprintf(
66
                'DELETE FROM %s ae',
67
                AstronomicalEntry::class
68
            )
69
        )->execute();
70
    }
71
72
    /** @return array<AstronomicalEntryInterface> */
73
    #[Override]
74
    public function getByUser(UserInterface $user): array
75
    {
76
        return $this->findBy(
77
            ['user_id' => $user->getId()]
78
        );
79
    }
80
}