Passed
Push — master ( 8387eb...5a11dc )
by Janko
07:59
created

CrewRepository::truncateAllCrew()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 9
ccs 0
cts 7
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\Spacecraft\SpacecraftRumpCategoryEnum;
10
use Stu\Orm\Entity\Crew;
11
use Stu\Orm\Entity\CrewAssignment;
12
use Stu\Orm\Entity\SpacecraftRump;
13
use Stu\Orm\Entity\Spacecraft;
14
use Stu\Orm\Entity\User;
15
16
/**
17
 * @extends EntityRepository<Crew>
18
 */
19
final class CrewRepository extends EntityRepository implements CrewRepositoryInterface
20
{
21
    #[Override]
22
    public function prototype(): Crew
23
    {
24
        return new Crew();
25
    }
26
27
    #[Override]
28
    public function save(Crew $post): void
29
    {
30
        $em = $this->getEntityManager();
31
32
        $em->persist($post);
33
    }
34
35
    #[Override]
36
    public function delete(Crew $post): void
37
    {
38
        $em = $this->getEntityManager();
39
40
        $em->remove($post);
41
    }
42
43 1
    #[Override]
44
    public function getAmountByUserAndShipRumpCategory(
45
        User $user,
46
        SpacecraftRumpCategoryEnum $shipRumpCategory
47
    ): int {
48 1
        return (int) $this->getEntityManager()
49 1
            ->createQuery(
50 1
                sprintf(
51 1
                    'SELECT COUNT(c.id) FROM %s c
52
                    JOIN %s ca
53
                    WITH ca.crew = c
54
                    JOIN %s sp
55
                    WITH ca.spacecraft = sp
56
                    JOIN %s r
57
                    WITH sp.rump = r
58
                    WHERE c.user = :user
59 1
                    AND r.category_id = :categoryId',
60 1
                    Crew::class,
61 1
                    CrewAssignment::class,
62 1
                    Spacecraft::class,
63 1
                    SpacecraftRump::class
64 1
                )
65 1
            )
66 1
            ->setParameters([
67 1
                'user' => $user,
68 1
                'categoryId' => $shipRumpCategory->value
69 1
            ])
70 1
            ->getSingleScalarResult();
71
    }
72
73
    #[Override]
74
    public function truncateByUser(int $userId): void
75
    {
76
        $this->getEntityManager()
77
            ->createQuery(
78
                sprintf(
79
                    'DELETE FROM %s c WHERE c.user_id = :userId',
80
                    Crew::class
81
                )
82
            )
83
            ->setParameter('userId', $userId)
84
            ->execute();
85
    }
86
}
87