Passed
Pull Request — master (#467)
by Alexander
10:48 queued 08:17
created

AbstractTableSchema::getName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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