OutboxMessageSchemaProvider::getSchemaFor()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 14
cp 0
rs 9.6666
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 OutboxMessageSchemaProvider 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', 'bigint', ['autoincrement' => true]);
26
            $table->addColumn('endpoint_id', 'integer');
27
            $table->addColumn('message_id', 'binary', ['length' => 16, 'fixed' => true]);
28
            $table->addColumn('is_dispatched', 'smallint');
29
            $table->addColumn('dispatched_at', 'datetime', ['notnull' => false]);
30
            $table->addColumn('transport_operations', 'text');
31
            $table->setPrimaryKey(['id']);
32
            $table->addUniqueIndex(['message_id', 'endpoint_id']);
33
            $table->addIndex(['dispatched_at', 'is_dispatched']);
34
        }
35
36
        return $this->schemas[$tableName];
37
    }
38
}
39