Completed
Pull Request — master (#345)
by
unknown
05:39
created

DBALWebsiteLookupService   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 42
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A lookup() 0 14 2
1
<?php
2
3
namespace CultuurNet\UDB3\Organizer;
4
5
use CultuurNet\UDB3\EventSourcing\DBAL\UniqueDBALEventStoreDecorator;
6
use Doctrine\DBAL\Connection;
7
use ValueObjects\Web\Url;
8
9
class DBALWebsiteLookupService implements WebsiteLookupServiceInterface
10
{
11
    /**
12
     * @var Connection
13
     */
14
    private $connection;
15
16
    /**
17
     * @var string
18
     */
19
    private $tableName;
20
21
    /**
22
     * @param Connection $connection
23
     * @param string $tableName
24
     */
25
    public function __construct(
26
        Connection $connection,
27
        $tableName
28
    ) {
29
        $this->connection = $connection;
30
        $this->tableName = (string) $tableName;
31
    }
32
33
    /**
34
     * @inheritdoc
35
     */
36
    public function lookup(Url $url)
37
    {
38
        $expr = $this->connection->getExpressionBuilder();
39
40
        $results = $this->connection->createQueryBuilder()
41
            ->select(UniqueDBALEventStoreDecorator::UUID_COLUMN)
42
            ->from($this->tableName)
43
            ->where($expr->eq(UniqueDBALEventStoreDecorator::UNIQUE_COLUMN, ':url'))
44
            ->setParameter(':url', (string) $url)
45
            ->execute();
46
47
        $uuid = $results->fetchColumn();
48
        return $uuid ? $uuid : null;
49
    }
50
}
51