Passed
Pull Request — 3.x (#31)
by
unknown
11:39
created

IndexParser   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 32
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getOptions() 0 5 1
A getName() 0 4 1
A isUnique() 0 3 1
A getField() 0 3 1
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