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

ForeignKeyParser::__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 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