Passed
Push — dev ( 79c88c...be1bbd )
by Nico
05:18
created

AllianceMemberJobRepository::getByJob()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
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 1
dl 0
loc 8
ccs 0
cts 6
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\Orm\Entity\AllianceMemberJob;
10
use Stu\Orm\Entity\User;
11
12
/**
13
 * @extends EntityRepository<AllianceMemberJob>
14
 */
15
final class AllianceMemberJobRepository extends EntityRepository implements AllianceMemberJobRepositoryInterface
16
{
17
    #[Override]
18
    public function prototype(): AllianceMemberJob
19
    {
20
        return new AllianceMemberJob();
21
    }
22
23
    #[Override]
24
    public function save(AllianceMemberJob $allianceMemberJob): void
25
    {
26
        $em = $this->getEntityManager();
27
        $em->persist($allianceMemberJob);
28
    }
29
30
    #[Override]
31
    public function delete(AllianceMemberJob $allianceMemberJob): void
32
    {
33
        $em = $this->getEntityManager();
34
        $em->remove($allianceMemberJob);
35
    }
36
37 9
    #[Override]
38
    public function getByUser(int $userId): array
39
    {
40 9
        return $this->createQueryBuilder('amj')
41 9
            ->where('amj.user = :userId')
42 9
            ->setParameter('userId', $userId)
43 9
            ->getQuery()
44 9
            ->getResult();
45
    }
46
47
    #[Override]
48
    public function getByJob(int $jobId): array
49
    {
50
        return $this->createQueryBuilder('amj')
51
            ->where('amj.job = :jobId')
52
            ->setParameter('jobId', $jobId)
53
            ->getQuery()
54
            ->getResult();
55
    }
56
57
    #[Override]
58
    public function truncateByUser(int $userId): void
59
    {
60
        $this->getEntityManager()->createQuery(
61
            sprintf(
62
                'DELETE FROM %s amj WHERE amj.user = :userId',
63
                AllianceMemberJob::class
64
            )
65
        )->setParameters([
66
            'userId' => $userId,
67
        ])->execute();
68
    }
69
70
    #[Override]
71
    public function truncateByJob(int $jobId): void
72
    {
73
        $this->getEntityManager()->createQuery(
74
            sprintf(
75
                'DELETE FROM %s amj WHERE amj.job = :jobId',
76
                AllianceMemberJob::class
77
            )
78
        )->setParameters([
79
            'jobId' => $jobId,
80
        ])->execute();
81
    }
82
83
    #[Override]
84
    public function getByUserAndJob(User $user, int $jobId): ?AllianceMemberJob
85
    {
86
        return $this->findOneBy([
87
            'user' => $user,
88
            'job' => $jobId,
89
        ]);
90
    }
91
}
92