Completed
Pull Request — master (#239)
by Luc
04:59
created

DBALReadRepository   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 5
dl 0
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLabelRelations() 0 17 2
A getAliases() 0 8 1
1
<?php
2
3
namespace CultuurNet\UDB3\Label\ReadModels\Relations\Repository\Doctrine;
4
5
use CultuurNet\UDB3\Label\ReadModels\Doctrine\AbstractDBALRepository;
6
use CultuurNet\UDB3\Label\ReadModels\Relations\Repository\LabelRelation;
7
use CultuurNet\UDB3\Label\ReadModels\Relations\Repository\ReadRepositoryInterface;
8
use CultuurNet\UDB3\Label\ValueObjects\LabelName;
9
10
class DBALReadRepository extends AbstractDBALRepository implements ReadRepositoryInterface
11
{
12
    /**
13
     * @inheritdoc
14
     */
15
    public function getLabelRelations(LabelName $labelName)
16
    {
17
        $aliases = $this->getAliases();
18
        $whereUuid = SchemaConfigurator::LABEL_NAME . ' = ?';
19
20
        $queryBuilder = $this->createQueryBuilder()->select($aliases)
21
            ->from($this->getTableName()->toNative())
22
            ->where($whereUuid)
23
            ->setParameters([$labelName->toNative()]);
24
25
        $statement = $queryBuilder->execute();
26
27
        while ($row = $statement->fetch(\PDO::FETCH_ASSOC)) {
28
            $labelRelation = LabelRelation::fromRelationalData($row);
29
            yield $labelRelation;
30
        }
31
    }
32
33
    /**
34
     * @return array
35
     */
36
    private function getAliases()
37
    {
38
        return [
39
            SchemaConfigurator::LABEL_NAME,
40
            SchemaConfigurator::RELATION_TYPE,
41
            SchemaConfigurator::RELATION_ID
42
        ];
43
    }
44
}
45