Completed
Push — master ( 13ce18...d30243 )
by Oleg
05:24
created

WriterUtility   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getColumns() 0 7 2
A getUniqueKeys() 0 10 3
1
<?php
2
declare(strict_types=1);
3
4
namespace SlayerBirden\DataFlow\Writer\Dbal;
5
6
use Doctrine\DBAL\Connection;
7
use Doctrine\DBAL\Schema\Index;
8
9
class WriterUtility implements WriterUtilityInterface
10
{
11
    /**
12
     * @var Connection
13
     */
14
    private $connection;
15
    private $columns = [];
16
    private $keys = [];
17
18 4
    public function __construct(Connection $connection)
19
    {
20 4
        $this->connection = $connection;
21 4
    }
22
23 3
    public function getColumns(string $table): array
24
    {
25 3
        if (!isset($this->columns[$table])) {
26 3
            $this->columns[$table] = $this->connection->getSchemaManager()->listTableColumns($table);
27
        }
28 3
        return $this->columns[$table];
29
    }
30
31 3
    public function getUniqueKeys(string $table): array
32
    {
33 3
        if (!isset($this->keys[$table])) {
34 3
            $allKeys = $this->connection->getSchemaManager()->listTableIndexes($table);
35 3
            $this->keys[$table] = array_filter($allKeys, function (Index $index) {
36 3
                return $index->isUnique() || $index->isPrimary();
37 3
            });
38
        }
39 3
        return $this->keys[$table];
40
    }
41
}
42