Test Failed
Push — dev ( 4abd48...6c393a )
by Janko
09:10
created

getWebOwningShipSystem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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