| Total Complexity | 55 |
| Total Lines | 282 |
| 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 |
||
| 35 | abstract class AbstractColumnSchema implements ColumnSchemaInterface |
||
| 36 | { |
||
| 37 | private bool $allowNull = false; |
||
| 38 | private bool $autoIncrement = false; |
||
| 39 | private string|null $comment = null; |
||
| 40 | private bool $computed = false; |
||
| 41 | private string $dbType = ''; |
||
| 42 | private mixed $defaultValue = null; |
||
| 43 | private array|null $enumValues = null; |
||
| 44 | private string|null $extra = null; |
||
| 45 | private bool $isPrimaryKey = false; |
||
| 46 | private string $name = ''; |
||
| 47 | private string|null $phpType = null; |
||
| 48 | private int|null $precision = null; |
||
| 49 | private int|null $scale = null; |
||
| 50 | private int|null $size = null; |
||
| 51 | private string $type = ''; |
||
| 52 | private bool $unsigned = false; |
||
| 53 | |||
| 54 | public function allowNull(bool $value): void |
||
| 55 | { |
||
| 56 | $this->allowNull = $value; |
||
| 57 | } |
||
| 58 | |||
| 59 | public function autoIncrement(bool $value): void |
||
| 60 | { |
||
| 61 | $this->autoIncrement = $value; |
||
| 62 | } |
||
| 63 | |||
| 64 | public function comment(string|null $value): void |
||
| 65 | { |
||
| 66 | $this->comment = $value; |
||
| 67 | } |
||
| 68 | |||
| 69 | public function computed(bool $value): void |
||
| 70 | { |
||
| 71 | $this->computed = $value; |
||
| 72 | } |
||
| 73 | |||
| 74 | public function dbType(string $value): void |
||
| 75 | { |
||
| 76 | $this->dbType = $value; |
||
| 77 | } |
||
| 78 | |||
| 79 | public function dbTypecast(mixed $value): mixed |
||
| 80 | { |
||
| 81 | /** |
||
| 82 | * the default implementation does the same as casting for PHP, but it should be possible to override this with |
||
| 83 | * annotation of explicit PDO type. |
||
| 84 | */ |
||
| 85 | return $this->typecast($value); |
||
| 86 | } |
||
| 87 | |||
| 88 | public function defaultValue(mixed $value): void |
||
| 89 | { |
||
| 90 | $this->defaultValue = $value; |
||
| 91 | } |
||
| 92 | |||
| 93 | public function enumValues(array|null $value): void |
||
| 94 | { |
||
| 95 | $this->enumValues = $value; |
||
| 96 | } |
||
| 97 | |||
| 98 | public function extra(string|null $value): void |
||
| 99 | { |
||
| 100 | $this->extra = $value; |
||
| 101 | } |
||
| 102 | |||
| 103 | public function getComment(): string|null |
||
| 104 | { |
||
| 105 | return $this->comment; |
||
| 106 | } |
||
| 107 | |||
| 108 | public function getDbType(): string |
||
| 109 | { |
||
| 110 | return $this->dbType; |
||
| 111 | } |
||
| 112 | |||
| 113 | public function getDefaultValue(): mixed |
||
| 114 | { |
||
| 115 | return $this->defaultValue; |
||
| 116 | } |
||
| 117 | |||
| 118 | public function getEnumValues(): array|null |
||
| 119 | { |
||
| 120 | return $this->enumValues; |
||
| 121 | } |
||
| 122 | |||
| 123 | public function getExtra(): string|null |
||
| 124 | { |
||
| 125 | return $this->extra; |
||
| 126 | } |
||
| 127 | |||
| 128 | public function getName(): string |
||
| 129 | { |
||
| 130 | return $this->name; |
||
| 131 | } |
||
| 132 | |||
| 133 | public function getPrecision(): int|null |
||
| 134 | { |
||
| 135 | return $this->precision; |
||
| 136 | } |
||
| 137 | |||
| 138 | public function getPhpType(): string|null |
||
| 139 | { |
||
| 140 | return $this->phpType; |
||
| 141 | } |
||
| 142 | |||
| 143 | public function getScale(): int|null |
||
| 146 | } |
||
| 147 | |||
| 148 | public function getSize(): int|null |
||
| 149 | { |
||
| 150 | return $this->size; |
||
| 151 | } |
||
| 152 | |||
| 153 | public function getType(): string |
||
| 154 | { |
||
| 155 | return $this->type; |
||
| 156 | } |
||
| 157 | |||
| 158 | public function isAllowNull(): bool |
||
| 161 | } |
||
| 162 | |||
| 163 | public function isAutoIncrement(): bool |
||
| 164 | { |
||
| 165 | return $this->autoIncrement; |
||
| 166 | } |
||
| 167 | |||
| 168 | public function isComputed(): bool |
||
| 169 | { |
||
| 170 | return $this->computed; |
||
| 171 | } |
||
| 172 | |||
| 173 | public function isPrimaryKey(): bool |
||
| 174 | { |
||
| 175 | return $this->isPrimaryKey; |
||
| 176 | } |
||
| 177 | |||
| 178 | public function isUnsigned(): bool |
||
| 179 | { |
||
| 180 | return $this->unsigned; |
||
| 181 | } |
||
| 182 | |||
| 183 | public function name(string $value): void |
||
| 184 | { |
||
| 185 | $this->name = $value; |
||
| 186 | } |
||
| 187 | |||
| 188 | public function phpType(string|null $value): void |
||
| 189 | { |
||
| 190 | $this->phpType = $value; |
||
| 191 | } |
||
| 192 | |||
| 193 | public function phpTypecast(mixed $value): mixed |
||
| 194 | { |
||
| 195 | return $this->typecast($value); |
||
| 196 | } |
||
| 197 | |||
| 198 | public function precision(int|null $value): void |
||
| 199 | { |
||
| 200 | $this->precision = $value; |
||
| 201 | } |
||
| 202 | |||
| 203 | public function primaryKey(bool $value): void |
||
| 204 | { |
||
| 205 | $this->isPrimaryKey = $value; |
||
| 206 | } |
||
| 207 | |||
| 208 | public function scale(int|null $value): void |
||
| 209 | { |
||
| 210 | $this->scale = $value; |
||
| 211 | } |
||
| 212 | |||
| 213 | public function size(int|null $value): void |
||
| 214 | { |
||
| 215 | $this->size = $value; |
||
| 216 | } |
||
| 217 | |||
| 218 | public function type(string $value): void |
||
| 221 | } |
||
| 222 | |||
| 223 | public function unsigned(bool $value): void |
||
| 224 | { |
||
| 225 | $this->unsigned = $value; |
||
| 226 | } |
||
| 227 | |||
| 228 | /** |
||
| 229 | * Converts the input value according to {@see phpType} after retrieval from the database. |
||
| 230 | * |
||
| 231 | * If the value is null or an {@see Expression}, it will not be converted. |
||
| 232 | * |
||
| 233 | * @param mixed $value input value |
||
| 234 | * |
||
| 235 | * @return mixed converted value |
||
| 236 | */ |
||
| 237 | protected function typecast(mixed $value): mixed |
||
| 303 | } |
||
| 304 | |||
| 305 | /** |
||
| 306 | * @return int[] array of numbers that represent possible PDO parameter types |
||
| 307 | */ |
||
| 308 | private function getPdoParamTypes(): array |
||
| 309 | { |
||
| 310 | return [ |
||
| 317 | ]; |
||
| 318 | } |
||
| 319 | } |
||
| 320 |