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

WriterUtility::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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