Passed
Push — dev ( 526fc6...1b8890 )
by Nico
35:41
created

AstroEntryRepository::getByShipLocation()   A

Complexity

Conditions 6
Paths 4

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

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