ServiceAttributeValueRepository   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Test Coverage

Coverage 5.56%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 39
c 1
b 0
f 0
dl 0
loc 92
ccs 3
cts 54
cp 0.0556
rs 10
wmc 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A getAttributeValuesForUser() 0 10 1
A persist() 0 2 1
A getAttributeValuesForRegistrationCode() 0 10 1
A remove() 0 2 1
A rollBack() 0 2 1
A beginTransaction() 0 2 1
A commit() 0 3 1
A getAttributeValuesForUserRole() 0 10 1
A getAttributeValuesForUserType() 0 10 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\ServiceAttributeRegistrationCodeValue;
6
use App\Entity\ServiceAttributeUserRoleValue;
7
use App\Entity\ServiceAttributeUserTypeValue;
8
use App\Entity\ServiceAttributeValue;
9
use App\Entity\ServiceAttributeValueInterface;
10
use App\Entity\User;
11
use App\Entity\RegistrationCode;
12
use App\Entity\UserRole;
13
use App\Entity\UserType;
14
use Doctrine\ORM\EntityManagerInterface;
15
16
class ServiceAttributeValueRepository implements ServiceAttributeValueRepositoryInterface, TransactionalRepositoryInterface {
17
18
    public function __construct(private EntityManagerInterface $em)
19 1
    {
20 1
    }
21 1
22
    /**
23
     * @inheritDoc
24
     */
25
    public function persist(ServiceAttributeValueInterface $attributeValue): void {
26
        $this->em->persist($attributeValue);
27
    }
28
29
    /**
30
     * @inheritDoc
31
     */
32
    public function remove(ServiceAttributeValueInterface $attributeValue): void {
33
        $this->em->remove($attributeValue);
34
    }
35
36
    public function beginTransaction(): void {
37
        $this->em->beginTransaction();
38
    }
39
40
    public function commit(): void {
41
        $this->em->commit();
42
        $this->em->flush();
43
    }
44
45
    public function rollBack(): void {
46
        $this->em->rollback();
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52
    public function getAttributeValuesForUser(User $user): array {
53
        $query = $this->em
54
            ->createQueryBuilder()
55
            ->select(['v', 'a'])
56
            ->from(ServiceAttributeValue::class, 'v')
57
            ->leftJoin('v.attribute', 'a')
58
            ->where('v.user = :user')
59
            ->setParameter('user', $user->getId());
60
61
        return $query->getQuery()->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
62
    }
63
64
65
    /**
66
     * @inheritDoc
67
     */
68
    public function getAttributeValuesForUserType(UserType $userType): array {
69
        $query = $this->em
70
            ->createQueryBuilder()
71
            ->select(['v', 'a'])
72
            ->from(ServiceAttributeUserTypeValue::class, 'v')
73
            ->leftJoin('v.attribute', 'a')
74
            ->where('v.userType = :type')
75
            ->setParameter('type', $userType->getId());
76
77
        return $query->getQuery()->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
78
    }
79
80
    /**
81
     * @inheritDoc
82
     */
83
    public function getAttributeValuesForUserRole(UserRole $userRole): array {
84
        $query = $this->em
85
            ->createQueryBuilder()
86
            ->select(['v', 'a'])
87
            ->from(ServiceAttributeUserRoleValue::class, 'v')
88
            ->leftJoin('v.attribute', 'a')
89
            ->where('v.userRole = :role')
90
            ->setParameter('role', $userRole->getId());
91
92
        return $query->getQuery()->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
93
    }
94
95
    /**
96
     * @inheritDoc
97
     */
98
    public function getAttributeValuesForRegistrationCode(RegistrationCode $code): array {
99
        $query = $this->em
100
            ->createQueryBuilder()
101
            ->select(['v', 'a'])
102
            ->from(ServiceAttributeRegistrationCodeValue::class, 'v')
103
            ->leftJoin('v.attribute', 'a')
104
            ->where('v.registrationCode = :code')
105
            ->setParameter('code', $code->getId());
106
107
        return $query->getQuery()->getResult();
0 ignored issues
show
Bug Best Practice introduced by
The expression return $query->getQuery()->getResult() could return the type integer which is incompatible with the type-hinted return array. Consider adding an additional type-check to rule them out.
Loading history...
108
    }
109
}