OutboxTablesCreatorFeatureInstallTask   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 73
ccs 23
cts 23
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
B install() 0 24 3
1
<?php
2
namespace PSB\Persistence\Doctrine1\Outbox;
3
4
5
use PSB\Core\Feature\FeatureInstallTaskInterface;
6
use PSB\Persistence\Doctrine1\LogicalConnection;
7
use PSB\Persistence\Doctrine1\Outbox\SchemaProvider\OutboxEndpointSchemaProvider;
8
use PSB\Persistence\Doctrine1\Outbox\SchemaProvider\OutboxMessageSchemaProvider;
9
10
class OutboxTablesCreatorFeatureInstallTask implements FeatureInstallTaskInterface
11
{
12
    /**
13
     * @var LogicalConnection
14
     */
15
    private $connection;
16
17
    /**
18
     * @var OutboxEndpointSchemaProvider
19
     */
20
    private $endpointSchemaProvider;
21
22
    /**
23
     * @var OutboxMessageSchemaProvider
24
     */
25
    private $messagesSchemaProvider;
26
27
    /**
28
     * @var string
29
     */
30
    private $endpointsTableName;
31
32
    /**
33
     * @var string
34
     */
35
    private $messagesTableName;
36
37
    /**
38
     * @param LogicalConnection            $connection
39
     * @param OutboxEndpointSchemaProvider $endpointSchemaProvider
40
     * @param OutboxMessageSchemaProvider  $messagesSchemaProvider
41
     * @param string                       $endpointsTableName
42
     * @param string                       $messagesTableName
43
     */
44 3
    public function __construct(
45
        LogicalConnection $connection,
46
        OutboxEndpointSchemaProvider $endpointSchemaProvider,
47
        OutboxMessageSchemaProvider $messagesSchemaProvider,
48
        $endpointsTableName,
49
        $messagesTableName
50
    ) {
51 3
        $this->connection = $connection;
52 3
        $this->endpointSchemaProvider = $endpointSchemaProvider;
53 3
        $this->messagesSchemaProvider = $messagesSchemaProvider;
54 3
        $this->endpointsTableName = $endpointsTableName;
55 3
        $this->messagesTableName = $messagesTableName;
56 3
    }
57
58 2
    public function install()
59
    {
60 2
        $messageSchema = $this->messagesSchemaProvider->getSchemaFor($this->messagesTableName);
61 2
        $endpointSchema = $this->endpointSchemaProvider->getSchemaFor($this->endpointsTableName);
62
63
        // is there a better way to atomically create in order to not compete with other endpoints?
64
        try {
65 2
            $this->connection->createTable(
66 2
                $messageSchema->getTableName(),
67 2
                $messageSchema->getDefinition(),
68 2
                $messageSchema->getOptions()
69 2
            );
70 2
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
71
        }
72
73
        try {
74 2
            $this->connection->createTable(
75 2
                $endpointSchema->getTableName(),
76 2
                $endpointSchema->getDefinition(),
77 2
                $endpointSchema->getOptions()
78 2
            );
79 2
        } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
80
        }
81 2
    }
82
}
83