Completed
Push — master ( eaf36c...f92548 )
by Marcel
03:19
created

ServiceAttributeRepository   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 28%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 44
ccs 7
cts 25
cp 0.28
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A persist() 0 3 1
A remove() 0 3 1
A __construct() 0 2 1
A getAttributes() 0 2 1
A getAttributesForServiceProvider() 0 10 1
A findAll() 0 4 1
1
<?php
2
3
namespace App\Repository;
4
5
use App\Entity\ServiceAttribute;
6
use Doctrine\ORM\EntityManagerInterface;
7
8
class ServiceAttributeRepository implements ServiceAttributeRepositoryInterface {
9
10
    private $em;
11
12 9
    public function __construct(EntityManagerInterface $objectManager) {
13 9
        $this->em = $objectManager;
14 9
    }
15
16
    /**
17
     * @inheritDoc
18
     */
19
    public function getAttributes() {
20
        return $this->findAll();
21
    }
22
23
    public function getAttributesForServiceProvider($entityId) {
24
        $queryBuilder = $this->em
25
            ->createQueryBuilder()
26
            ->select(['a', 's'])
27
            ->from(ServiceAttribute::class, 'a')
28
            ->leftJoin('a.services', 's')
29
            ->where('s.entityId = :entityId')
30
            ->setParameter('entityId', $entityId);
31
32
        return $queryBuilder->getQuery()->getResult();
33
    }
34
35
    /**
36
     * @inheritDoc
37
     */
38 1
    public function findAll() {
39 1
        return $this->em
40 1
            ->getRepository(ServiceAttribute::class)
41 1
            ->findAll();
42
    }
43
44
    public function persist(ServiceAttribute $attribute) {
45
        $this->em->persist($attribute);
46
        $this->em->flush();
47
    }
48
49
    public function remove(ServiceAttribute $attribute) {
50
        $this->em->remove($attribute);
51
        $this->em->flush();
52
    }
53
}