| Total Complexity | 50 |
| Total Lines | 259 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like AbstractColumnSchema often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use AbstractColumnSchema, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 43 | abstract class AbstractColumnSchema implements ColumnSchemaInterface |
||
| 44 | { |
||
| 45 | public function __construct(string $name) |
||
| 46 | { |
||
| 47 | $this->name = $name; |
||
| 48 | } |
||
| 49 | |||
| 50 | private bool $allowNull = false; |
||
| 51 | private bool $autoIncrement = false; |
||
| 52 | private string|null $comment = null; |
||
| 53 | private bool $computed = false; |
||
| 54 | private string|null $dbType = null; |
||
| 55 | private mixed $defaultValue = null; |
||
| 56 | private array|null $enumValues = null; |
||
| 57 | private string|null $extra = null; |
||
| 58 | private bool $isPrimaryKey = false; |
||
| 59 | private string $name; |
||
| 60 | private string|null $phpType = null; |
||
| 61 | private int|null $precision = null; |
||
| 62 | private int|null $scale = null; |
||
| 63 | private int|null $size = null; |
||
| 64 | private string $type = ''; |
||
| 65 | private bool $unsigned = false; |
||
| 66 | |||
| 67 | public function allowNull(bool $value): void |
||
| 68 | { |
||
| 69 | $this->allowNull = $value; |
||
| 70 | } |
||
| 71 | |||
| 72 | public function autoIncrement(bool $value): void |
||
| 73 | { |
||
| 74 | $this->autoIncrement = $value; |
||
| 75 | } |
||
| 76 | |||
| 77 | public function comment(string|null $value): void |
||
| 78 | { |
||
| 79 | $this->comment = $value; |
||
| 80 | } |
||
| 81 | |||
| 82 | public function computed(bool $value): void |
||
| 83 | { |
||
| 84 | $this->computed = $value; |
||
| 85 | } |
||
| 86 | |||
| 87 | public function dbType(string|null $value): void |
||
| 88 | { |
||
| 89 | $this->dbType = $value; |
||
| 90 | } |
||
| 91 | |||
| 92 | public function dbTypecast(mixed $value): mixed |
||
| 93 | { |
||
| 94 | /** |
||
| 95 | * The default implementation does the same as casting for PHP, but it should be possible to override this with |
||
| 96 | * annotation of an explicit PDO type. |
||
| 97 | */ |
||
| 98 | return $this->typecast($value); |
||
| 99 | } |
||
| 100 | |||
| 101 | public function defaultValue(mixed $value): void |
||
| 102 | { |
||
| 103 | $this->defaultValue = $value; |
||
| 104 | } |
||
| 105 | |||
| 106 | public function enumValues(array|null $value): void |
||
| 107 | { |
||
| 108 | $this->enumValues = $value; |
||
| 109 | } |
||
| 110 | |||
| 111 | public function extra(string|null $value): void |
||
| 112 | { |
||
| 113 | $this->extra = $value; |
||
| 114 | } |
||
| 115 | |||
| 116 | public function getComment(): string|null |
||
| 117 | { |
||
| 118 | return $this->comment; |
||
| 119 | } |
||
| 120 | |||
| 121 | public function getDbType(): string|null |
||
| 122 | { |
||
| 123 | return $this->dbType; |
||
| 124 | } |
||
| 125 | |||
| 126 | public function getDefaultValue(): mixed |
||
| 127 | { |
||
| 128 | return $this->defaultValue; |
||
| 129 | } |
||
| 130 | |||
| 131 | public function getEnumValues(): array|null |
||
| 132 | { |
||
| 133 | return $this->enumValues; |
||
| 134 | } |
||
| 135 | |||
| 136 | public function getExtra(): string|null |
||
| 137 | { |
||
| 138 | return $this->extra; |
||
| 139 | } |
||
| 140 | |||
| 141 | public function getName(): string |
||
| 142 | { |
||
| 143 | return $this->name; |
||
| 144 | } |
||
| 145 | |||
| 146 | public function getPrecision(): int|null |
||
| 147 | { |
||
| 148 | return $this->precision; |
||
| 149 | } |
||
| 150 | |||
| 151 | public function getPhpType(): string|null |
||
| 152 | { |
||
| 153 | return $this->phpType; |
||
| 154 | } |
||
| 155 | |||
| 156 | public function getScale(): int|null |
||
| 157 | { |
||
| 158 | return $this->scale; |
||
| 159 | } |
||
| 160 | |||
| 161 | public function getSize(): int|null |
||
| 162 | { |
||
| 163 | return $this->size; |
||
| 164 | } |
||
| 165 | |||
| 166 | public function getType(): string |
||
| 167 | { |
||
| 168 | return $this->type; |
||
| 169 | } |
||
| 170 | |||
| 171 | public function isAllowNull(): bool |
||
| 172 | { |
||
| 173 | return $this->allowNull; |
||
| 174 | } |
||
| 175 | |||
| 176 | public function isAutoIncrement(): bool |
||
| 177 | { |
||
| 178 | return $this->autoIncrement; |
||
| 179 | } |
||
| 180 | |||
| 181 | public function isComputed(): bool |
||
| 182 | { |
||
| 183 | return $this->computed; |
||
| 184 | } |
||
| 185 | |||
| 186 | public function isPrimaryKey(): bool |
||
| 187 | { |
||
| 188 | return $this->isPrimaryKey; |
||
| 189 | } |
||
| 190 | |||
| 191 | public function isUnsigned(): bool |
||
| 192 | { |
||
| 193 | return $this->unsigned; |
||
| 194 | } |
||
| 195 | |||
| 196 | public function phpType(string|null $value): void |
||
| 197 | { |
||
| 198 | $this->phpType = $value; |
||
| 199 | } |
||
| 200 | |||
| 201 | public function phpTypecast(mixed $value): mixed |
||
| 202 | { |
||
| 203 | return $this->typecast($value); |
||
| 204 | } |
||
| 205 | |||
| 206 | public function precision(int|null $value): void |
||
| 207 | { |
||
| 208 | $this->precision = $value; |
||
| 209 | } |
||
| 210 | |||
| 211 | public function primaryKey(bool $value): void |
||
| 212 | { |
||
| 213 | $this->isPrimaryKey = $value; |
||
| 214 | } |
||
| 215 | |||
| 216 | public function scale(int|null $value): void |
||
| 217 | { |
||
| 218 | $this->scale = $value; |
||
| 219 | } |
||
| 220 | |||
| 221 | public function size(int|null $value): void |
||
| 222 | { |
||
| 223 | $this->size = $value; |
||
| 224 | } |
||
| 225 | |||
| 226 | public function type(string $value): void |
||
| 229 | } |
||
| 230 | |||
| 231 | public function unsigned(bool $value): void |
||
| 232 | { |
||
| 233 | $this->unsigned = $value; |
||
| 234 | } |
||
| 235 | |||
| 236 | /** |
||
| 237 | * Converts the input value according to {@see phpType} after retrieval from the database. |
||
| 238 | * |
||
| 239 | * If the value is null or an {@see Expression}, it won't be converted. |
||
| 240 | * |
||
| 241 | * @param mixed $value The value to be converted. |
||
| 242 | * |
||
| 243 | * @return mixed The converted value. |
||
| 244 | */ |
||
| 245 | protected function typecast(mixed $value): mixed |
||
| 302 | } |
||
| 303 | } |
||
| 304 |