Test Failed
Push — dev ( 0a21cd...88787c )
by Janko
08:43
created

SpacecraftSystemRepository::getShipSystem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 11
nc 1
nop 2
dl 0
loc 16
ccs 0
cts 13
cp 0
crap 2
rs 9.9
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\Component\Spacecraft\System\SpacecraftSystemTypeEnum;
10
use Stu\Orm\Entity\SpacecraftSystem;
11
12
/**
13
 * @extends EntityRepository<SpacecraftSystem>
14
 */
15
final class SpacecraftSystemRepository extends EntityRepository implements SpacecraftSystemRepositoryInterface
16
{
17
    #[Override]
18
    public function prototype(): SpacecraftSystem
19
    {
20
        return new SpacecraftSystem();
21
    }
22
23
    #[Override]
24 1
    public function save(SpacecraftSystem $post): void
25
    {
26
        $em = $this->getEntityManager();
27 1
28
        $em->persist($post);
29 1
    }
30
31
    #[Override]
32
    public function delete(SpacecraftSystem $post): void
33
    {
34
        $em = $this->getEntityManager();
35
36
        $em->remove($post);
37
    }
38
39
    #[Override]
40
    public function getByShip(int $shipId): array
41
    {
42
        return $this->findBy(
43
            ['spacecraft_id' => $shipId],
44
            ['system_type' => 'asc']
45
        );
46
    }
47
48
    #[Override]
49
    public function getTrackingShipSystems(int $targetId): array
50
    {
51
        return $this->getShipSystem(
52
            sprintf('%%"targetId":%d%%', $targetId),
53
            SpacecraftSystemTypeEnum::TRACKER
54
        );
55
    }
56
57
    #[Override]
58
    public function getWebConstructingShipSystems(int $webId): array
59
    {
60
        return $this->getShipSystem(
61
            sprintf('%%"webUnderConstructionId":%d%%', $webId),
62
            SpacecraftSystemTypeEnum::THOLIAN_WEB
63
        );
64
    }
65
66
    /**
67
     * @return array<SpacecraftSystem>
68
     */
69
    private function getShipSystem(string $target, SpacecraftSystemTypeEnum $type): array
70
    {
71
        return $this->getEntityManager()
72
            ->createQuery(
73
                sprintf(
74
                    'SELECT ss FROM %s ss
75
                    WHERE ss.system_type = :systemType
76
                    AND ss.data LIKE :target',
77
                    SpacecraftSystem::class
78
                )
79
            )
80
            ->setParameters([
81
                'systemType' => $type,
82
                'target' => $target
83
            ])
84
            ->getResult();
85
    }
86
87
    #[Override]
88
    public function getWebOwningShipSystem(int $webId): ?SpacecraftSystem
89
    {
90
        return $this->getEntityManager()
91
            ->createQuery(
92
                sprintf(
93
                    'SELECT ss FROM %s ss
94
                    WHERE ss.system_type = :systemType
95
                    AND ss.data LIKE :target',
96
                    SpacecraftSystem::class
97
                )
98
            )
99
            ->setParameters([
100
                'systemType' => SpacecraftSystemTypeEnum::THOLIAN_WEB,
101
                'target' => sprintf('%%"ownedWebId":%d%%', $webId)
102
            ])
103
            ->getOneOrNullResult();
104
    }
105
106
    #[Override]
107
    public function truncateByShip(int $shipId): void
108
    {
109
        $this->getEntityManager()
110
            ->createQuery(
111
                sprintf(
112
                    'DELETE FROM %s s WHERE s.spacecraft_id = :shipId',
113
                    SpacecraftSystem::class
114
                )
115
            )
116
            ->setParameter('shipId', $shipId)
117
            ->execute();
118
    }
119
}
120