Passed
Pull Request — 3.x (#31)
by
unknown
18:33 queued 03:34
created

ForeignKeyParser   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 21
c 1
b 0
f 0
dl 0
loc 58
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getInnerKeys() 0 3 1
A getName() 0 8 1
A getInnerTable() 0 3 1
A getOptions() 0 6 1
A getOuterKeys() 0 3 1
A getOnDelete() 0 3 1
A __construct() 0 4 1
A getOnUpdate() 0 3 1
A getOuterTable() 0 3 1
1
<?php
2
3
4
declare(strict_types=1);
5
6
namespace Cycle\Migrations\V2;
7
8
class ForeignKeyParser extends ForeignKey
9
{
10
    private ForeignKey $foreignKey;
11
    private string $tableName;
12
13
    public function __construct(ForeignKey $foreignKey, string $tableName)
14
    {
15
        $this->foreignKey = $foreignKey;
16
        $this->tableName = $tableName;
17
    }
18
19
    public function getName(): string
20
    {
21
        return $this->index->name ?? sprintf(
0 ignored issues
show
Bug Best Practice introduced by
The property index does not exist on Cycle\Migrations\V2\ForeignKeyParser. Did you maybe forget to declare it?
Loading history...
22
                '%s_%s_%s_%s_fk',
23
                $this->getInnerTable(),
24
                $this->getInnerKeys()[0],
25
                $this->getOuterTable(),
26
                $this->getOuterKeys()[0]
27
            );
28
    }
29
30
    public function getInnerTable(): string
31
    {
32
        return $this->tableName;
33
    }
34
35
    public function getInnerKeys(): array
36
    {
37
        return $this->foreignKey->innerKeys;
38
    }
39
40
    public function getOuterTable(): string
41
    {
42
        return $this->foreignKey->outerTable;
43
    }
44
45
    public function getOuterKeys(): array
46
    {
47
        return $this->foreignKey->outerKeys;
48
    }
49
50
    public function getOnDelete(): string
51
    {
52
        return $this->foreignKey->onDelete->value();
53
    }
54
55
    public function getOnUpdate(): string
56
    {
57
        return $this->foreignKey->onUpdate->value();
58
    }
59
60
    public function getOptions(): array
61
    {
62
        return [
63
            'name' => $this->getName(),
64
            'delete' => $this->getOnDelete(),
65
            'update' => $this->getOnUpdate(),
66
        ];
67
    }
68
}
69