Passed
Push — master ( c761cc...25dc06 )
by Def
02:14
created

AbstractTableSchema::compositeForeignKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Schema;
6
7
use Yiisoft\Db\Exception\NotSupportedException;
8
9
use function array_keys;
10
11
/**
12
 * Represents the metadata of a database table.
13
 */
14
abstract class AbstractTableSchema implements TableSchemaInterface
15
{
16
    private string|null $schemaName = null;
17
    private string $name = '';
18
    private string|null $fullName = null;
19
    private string|null $comment = null;
20
    private string|null $sequenceName = null;
21
    /** @psalm-var string[] */
22
    private array $primaryKey = [];
23
    /** @psalm-var ColumnSchemaInterface[] */
24
    private array $columns = [];
25
    /** @psalm-var array<array-key, array> */
26
    protected array $foreignKeys = [];
27
    protected string|null $createSql = null;
28
    private string|null $catalogName = null;
29
    private string|null $serverName = null;
30
31
    public function getColumn(string $name): ColumnSchemaInterface|null
32
    {
33
        return $this->columns[$name] ?? null;
34
    }
35
36
    public function getColumnNames(): array
37
    {
38
        return array_keys($this->columns);
39
    }
40
41
    public function getSchemaName(): string|null
42
    {
43
        return $this->schemaName;
44
    }
45
46
    public function getName(): string
47
    {
48
        return $this->name;
49
    }
50
51
    public function getFullName(): string|null
52
    {
53
        return $this->fullName;
54
    }
55
56
    public function getSequenceName(): string|null
57
    {
58
        return $this->sequenceName;
59
    }
60
61
    public function getPrimaryKey(): array
62
    {
63
        return $this->primaryKey;
64
    }
65
66
    public function getColumns(): array
67
    {
68
        return $this->columns;
69
    }
70
71
    public function getComment(): string|null
72
    {
73
        return $this->comment;
74
    }
75
76
    public function schemaName(string|null $value): void
77
    {
78
        $this->schemaName = $value;
79
    }
80
81
    public function name(string $value): void
82
    {
83
        $this->name = $value;
84
    }
85
86
    public function fullName(string|null $value): void
87
    {
88
        $this->fullName = $value;
89
    }
90
91
    public function comment(string|null $value): void
92
    {
93
        $this->comment = $value;
94
    }
95
96
    public function sequenceName(string|null $value): void
97
    {
98
        $this->sequenceName = $value;
99
    }
100
101
    public function primaryKey(string $value): void
102
    {
103
        $this->primaryKey[] = $value;
104
    }
105
106
    public function column(string $name, ColumnSchemaInterface $value): void
107
    {
108
        $this->columns[$name] = $value;
109
    }
110
111
    public function getCatalogName(): string|null
112
    {
113
        return $this->catalogName;
114
    }
115
116
    public function catalogName(string|null $value): void
117
    {
118
        $this->catalogName = $value;
119
    }
120
121
    public function getServerName(): string|null
122
    {
123
        return $this->serverName;
124
    }
125
126
    public function serverName(string|null $value): void
127
    {
128
        $this->serverName = $value;
129
    }
130
131
    public function getCreateSql(): string|null
132
    {
133
        return $this->createSql;
134
    }
135
136
    public function createSql(string $sql): void
137
    {
138
        $this->createSql = $sql;
139
    }
140
141
    public function getForeignKeys(): array
142
    {
143
        return $this->foreignKeys;
144
    }
145
146
    public function foreignKeys(array $value): void
147
    {
148
        $this->foreignKeys = $value;
149
    }
150
151
    public function foreignKey(string|int $id, array $to): void
152
    {
153
        $this->foreignKeys[$id] = $to;
154
    }
155
156
    public function compositeForeignKey(int $id, string $from, string $to): void
157
    {
158
        throw new NotSupportedException(static::class . ' does not support composite FK.');
159
    }
160
}
161