Passed
Pull Request — master (#752)
by Sergei
02:26
created

AbstractColumnSchema   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 185
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 49
c 1
b 0
f 0
dl 0
loc 185
rs 9.68
wmc 34

34 Methods

Rating   Name   Duplication   Size   Complexity  
A primaryKey() 0 3 1
A allowNull() 0 3 1
A __construct() 0 2 1
A scale() 0 3 1
A getPrecision() 0 3 1
A isAllowNull() 0 3 1
A getType() 0 3 1
A extra() 0 3 1
A getName() 0 3 1
A comment() 0 3 1
A isComputed() 0 3 1
A getPhpType() 0 3 1
A getScale() 0 3 1
A isAutoIncrement() 0 3 1
A dbTypecast() 0 3 1
A phpTypecast() 0 3 1
A type() 0 3 1
A getComment() 0 3 1
A computed() 0 3 1
A getEnumValues() 0 3 1
A defaultValue() 0 3 1
A unsigned() 0 3 1
A getSize() 0 3 1
A size() 0 3 1
A getDbType() 0 3 1
A phpType() 0 3 1
A dbType() 0 3 1
A precision() 0 3 1
A getExtra() 0 3 1
A isUnsigned() 0 3 1
A autoIncrement() 0 3 1
A enumValues() 0 3 1
A getDefaultValue() 0 3 1
A isPrimaryKey() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Schema\Column;
6
7
/**
8
 * Represents the metadata of a column in a database table.
9
 *
10
 * It provides information about the column's name, type, size, precision, and other details.
11
 *
12
 * The `ColumnSchema` class is used to store and retrieve metadata about a column in a database table.
13
 *
14
 * It's typically used in conjunction with the TableSchema class, which represents the metadata of a database table as a
15
 * whole.
16
 *
17
 * Here is an example of how to use the `ColumnSchema` class:
18
 *
19
 * ```php
20
 * use Yiisoft\Db\Schema\ColumnSchema;
21
 *
22
 * $column = new ColumnSchema();
23
 * $column->name('id');
24
 * $column->allowNull(false);
25
 * $column->dbType('int(11)');
26
 * $column->phpType('integer');
27
 * $column->type('integer');
28
 * $column->defaultValue(0);
29
 * $column->autoIncrement(true);
30
 * $column->primaryKey(true);
31
 * ``
32
 */
33
abstract class AbstractColumnSchema implements ColumnSchemaInterface
34
{
35
    private bool $allowNull = false;
36
    private bool $autoIncrement = false;
37
    private string|null $comment = null;
38
    private bool $computed = false;
39
    private string|null $dbType = null;
40
    private mixed $defaultValue = null;
41
    private array|null $enumValues = null;
42
    private string|null $extra = null;
43
    private bool $isPrimaryKey = false;
44
    private string|null $phpType = null;
45
    private int|null $precision = null;
46
    private int|null $scale = null;
47
    private int|null $size = null;
48
    private string $type = '';
49
    private bool $unsigned = false;
50
51
    public function __construct(private string $name)
52
    {
53
    }
54
55
    public function allowNull(bool $value): void
56
    {
57
        $this->allowNull = $value;
58
    }
59
60
    public function autoIncrement(bool $value): void
61
    {
62
        $this->autoIncrement = $value;
63
    }
64
65
    public function comment(string|null $value): void
66
    {
67
        $this->comment = $value;
68
    }
69
70
    public function computed(bool $value): void
71
    {
72
        $this->computed = $value;
73
    }
74
75
    public function dbType(string|null $value): void
76
    {
77
        $this->dbType = $value;
78
    }
79
80
    public function dbTypecast(mixed $value): mixed
81
    {
82
        return $value;
83
    }
84
85
    public function defaultValue(mixed $value): void
86
    {
87
        $this->defaultValue = $value;
88
    }
89
90
    public function enumValues(array|null $value): void
91
    {
92
        $this->enumValues = $value;
93
    }
94
95
    public function extra(string|null $value): void
96
    {
97
        $this->extra = $value;
98
    }
99
100
    public function getComment(): string|null
101
    {
102
        return $this->comment;
103
    }
104
105
    public function getDbType(): string|null
106
    {
107
        return $this->dbType;
108
    }
109
110
    public function getDefaultValue(): mixed
111
    {
112
        return $this->defaultValue;
113
    }
114
115
    public function getEnumValues(): array|null
116
    {
117
        return $this->enumValues;
118
    }
119
120
    public function getExtra(): string|null
121
    {
122
        return $this->extra;
123
    }
124
125
    public function getName(): string
126
    {
127
        return $this->name;
128
    }
129
130
    public function getPrecision(): int|null
131
    {
132
        return $this->precision;
133
    }
134
135
    public function getPhpType(): string|null
136
    {
137
        return $this->phpType;
138
    }
139
140
    public function getScale(): int|null
141
    {
142
        return $this->scale;
143
    }
144
145
    public function getSize(): int|null
146
    {
147
        return $this->size;
148
    }
149
150
    public function getType(): string
151
    {
152
        return $this->type;
153
    }
154
155
    public function isAllowNull(): bool
156
    {
157
        return $this->allowNull;
158
    }
159
160
    public function isAutoIncrement(): bool
161
    {
162
        return $this->autoIncrement;
163
    }
164
165
    public function isComputed(): bool
166
    {
167
        return $this->computed;
168
    }
169
170
    public function isPrimaryKey(): bool
171
    {
172
        return $this->isPrimaryKey;
173
    }
174
175
    public function isUnsigned(): bool
176
    {
177
        return $this->unsigned;
178
    }
179
180
    public function phpType(string|null $value): void
181
    {
182
        $this->phpType = $value;
183
    }
184
185
    public function phpTypecast(mixed $value): mixed
186
    {
187
        return $value;
188
    }
189
190
    public function precision(int|null $value): void
191
    {
192
        $this->precision = $value;
193
    }
194
195
    public function primaryKey(bool $value): void
196
    {
197
        $this->isPrimaryKey = $value;
198
    }
199
200
    public function scale(int|null $value): void
201
    {
202
        $this->scale = $value;
203
    }
204
205
    public function size(int|null $value): void
206
    {
207
        $this->size = $value;
208
    }
209
210
    public function type(string $value): void
211
    {
212
        $this->type = $value;
213
    }
214
215
    public function unsigned(bool $value): void
216
    {
217
        $this->unsigned = $value;
218
    }
219
}
220