Passed
Push — master ( 77a570...adeb98 )
by Nico
26:43
created

ShipSystemRepository::getByShipAndModule()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 4
cp 0
crap 2
rs 10
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\Ship\System\ShipSystemTypeEnum;
10
use Stu\Orm\Entity\ShipSystem;
11
use Stu\Orm\Entity\ShipSystemInterface;
12
13
/**
14
 * @extends EntityRepository<ShipSystem>
15
 */
16
final class ShipSystemRepository extends EntityRepository implements ShipSystemRepositoryInterface
17
{
18
    #[Override]
19
    public function prototype(): ShipSystemInterface
20
    {
21
        return new ShipSystem();
22
    }
23
24
    #[Override]
25
    public function save(ShipSystemInterface $post): void
26
    {
27
        $em = $this->getEntityManager();
28
29
        $em->persist($post);
30
    }
31
32
    #[Override]
33
    public function delete(ShipSystemInterface $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
            ['ship_id' => $shipId],
45
            ['system_type' => 'asc']
46
        );
47
    }
48
49
    #[Override]
50
    public function getByShipAndModule(int $shipId, int $moduleId): ?ShipSystemInterface
51
    {
52
        return $this->findOneBy([
53
            'ship_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
                    ShipSystem::class
68
                )
69
            )
70
            ->setParameters([
71
                'systemType' => ShipSystemTypeEnum::SYSTEM_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
                    ShipSystem::class
87
                )
88
            )
89
            ->setParameters([
90
                'systemType' => ShipSystemTypeEnum::SYSTEM_THOLIAN_WEB,
91
                'target' => sprintf('%%"webUnderConstructionId":%d%%', $webId)
92
            ])
93
            ->getResult();
94
    }
95
96
    #[Override]
97
    public function truncateByShip(int $shipId): void
98
    {
99
        $this->getEntityManager()
100
            ->createQuery(
101
                sprintf(
102
                    'DELETE FROM %s s WHERE s.ship_id = :shipId',
103
                    ShipSystem::class
104
                )
105
            )
106
            ->setParameter('shipId', $shipId)
107
            ->execute();
108
    }
109
}