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

AllianceApplicationRepository   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 0 %

Test Coverage

Coverage 27.27%

Importance

Changes 0
Metric Value
eloc 42
dl 0
loc 76
ccs 12
cts 44
cp 0.2727
rs 10
c 0
b 0
f 0
wmc 8

8 Methods

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