Passed
Pull Request — 3.x (#31)
by
unknown
14:21
created

IndexParser::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 2
1
<?php
2
3
4
declare(strict_types=1);
5
6
namespace Cycle\Migrations\V2;
7
8
class IndexParser extends Index
9
{
10
    private Index $index;
11
    private string $tableName;
12
13
    public function __construct(Index $index, string $tableName)
14
    {
15
        $this->index = $index;
16
        $this->tableName = $tableName;
17
    }
18
19
    public function getField(): array
20
    {
21
        return $this->index->fields;
22
    }
23
24
    public function getName(): string
25
    {
26
        return $this->index->name
27
            ?? sprintf('%s_%s_index', $this->tableName, implode('_', $this->getField()));
28
    }
29
30
    public function isUnique(): bool
31
    {
32
        return $this->index->unique;
33
    }
34
35
    public function getOptions(): array
36
    {
37
        return [
38
            'name' => $this->getName(),
39
            'unique' => $this->isUnique(),
40
        ];
41
    }
42
}
43