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

ReadRepository::getLabelRelations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 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 ValueObjects\Identity\UUID;
9
10
class ReadRepository extends AbstractDBALRepository implements ReadRepositoryInterface
11
{
12
    /**
13
     * @inheritdoc
14
     */
15
    public function getLabelRelations(UUID $labelId)
16
    {
17
        $aliases = $this->getAliases();
18
        $whereUuid = SchemaConfigurator::UUID_COLUMN . ' = ?';
19
20
        $queryBuilder = $this->createQueryBuilder()->select($aliases)
21
            ->from($this->getTableName()->toNative())
22
            ->where($whereUuid)
23
            ->setParameters([$labelId]);
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::UUID_COLUMN,
40
            SchemaConfigurator::RELATION_TYPE_COLUMN,
41
            SchemaConfigurator::RELATION_ID_COLUMN
42
        ];
43
    }
44
}
45