OutboxEndpointSchemaProvider::getSchemaFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 10
cp 0
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
namespace PSB\Persistence\Doctrine2\Outbox\SchemaProvider;
3
4
5
use Doctrine\DBAL\Schema\Schema;
6
use PSB\Persistence\Doctrine2\SchemaProviderInterface;
7
8
class OutboxEndpointSchemaProvider implements SchemaProviderInterface
9
{
10
    /**
11
     * @var Schema[]
12
     */
13
    private $schemas = [];
14
15
    /**
16
     * @param string $tableName
17
     *
18
     * @return Schema
19
     */
20
    public function getSchemaFor($tableName)
21
    {
22
        if (!isset($this->schemas[$tableName])) {
23
            $this->schemas[$tableName] = new Schema();
24
            $table = $this->schemas[$tableName]->createTable($tableName);
25
            $table->addColumn('id', 'integer', ['autoincrement' => true]);
26
            $table->addColumn('lookup_hash', 'binary', ['length' => 16, 'fixed' => true]);
27
            $table->addColumn('name', 'text');
28
            $table->setPrimaryKey(['id']);
29
            $table->addUniqueIndex(['lookup_hash']);
30
        }
31
32
        return $this->schemas[$tableName];
33
    }
34
}
35