Completed
Push — master ( 73f449...670c74 )
by Kristof
04:33
created

SchemaConfigurator::configure()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 20
rs 9.4285
cc 1
eloc 13
nc 1
nop 1
1
<?php
2
/**
3
 * @file
4
 */
5
6
namespace CultuurNet\UDB3\Offer\ReadModel\Permission\Doctrine;
7
8
use CultuurNet\UDB3\Doctrine\DBAL\SchemaConfiguratorInterface;
9
use Doctrine\DBAL\Schema\AbstractSchemaManager;
10
use ValueObjects\String\String as StringLiteral;
11
12
class SchemaConfigurator implements SchemaConfiguratorInterface
13
{
14
    /**
15
     * @var StringLiteral
16
     */
17
    protected $tableName;
18
19
    /**
20
     * @var StringLiteral
21
     */
22
    protected $idField;
23
24
    /**
25
     * @param StringLiteral $tableName
26
     * @param StringLiteral $idField
27
     */
28
    public function __construct(StringLiteral $tableName, StringLiteral $idField)
29
    {
30
        $this->tableName = $tableName;
31
        $this->idField = $idField;
32
    }
33
34
    /**
35
     * @inheritdoc
36
     */
37
    public function configure(AbstractSchemaManager $schemaManager)
38
    {
39
        $schema = $schemaManager->createSchema();
40
        $table = $schema->createTable($this->tableName->toNative());
41
42
        $table->addColumn(
43
            $this->idField->toNative(),
44
            'guid',
45
            array('length' => 36, 'notnull' => true)
46
        );
47
        $table->addColumn(
48
            'user_id',
49
            'guid',
50
            array('length' => 36, 'notnull' => true)
51
        );
52
53
        $table->setPrimaryKey([$this->idField->toNative(), 'user_id']);
54
55
        $schemaManager->createTable($table);
56
    }
57
}
58