Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 16 | class Mysql extends Dbal |
||
| 17 | { |
||
| 18 | protected static $typeMapping = [ |
||
| 19 | 'tinyint' => Type\Number::class, |
||
| 20 | 'smallint' => Type\Number::class, |
||
| 21 | 'mediumint' => Type\Number::class, |
||
| 22 | 'int' => Type\Number::class, |
||
| 23 | 'bigint' => Type\Number::class, |
||
| 24 | 'decimal' => Type\Number::class, |
||
| 25 | 'float' => Type\Number::class, |
||
| 26 | 'double' => Type\Number::class, |
||
| 27 | |||
| 28 | 'varchar' => Type\VarChar::class, |
||
| 29 | 'char' => Type\VarChar::class, |
||
| 30 | |||
| 31 | 'text' => Type\Text::class, |
||
| 32 | 'tinytext' => Type\Text::class, |
||
| 33 | 'mediumtext' => Type\Text::class, |
||
| 34 | 'longtext' => Type\Text::class, |
||
| 35 | |||
| 36 | 'datetime' => Type\DateTime::class, |
||
| 37 | 'date' => Type\DateTime::class, |
||
| 38 | 'timestamp' => Type\DateTime::class, |
||
| 39 | |||
| 40 | 'time' => Type\Time::class, |
||
| 41 | 'enum' => Type\Enum::class, |
||
| 42 | 'set' => Type\Set::class, |
||
| 43 | 'json' => Type\Json::class, |
||
| 44 | 6 | ]; |
|
| 45 | |||
| 46 | 6 | protected static $compositeWhereInTemplate = '(%s) IN (%s)'; |
|
| 47 | 6 | ||
| 48 | public function insertAndSyncWithAutoInc(Entity ...$entities) |
||
| 74 | |||
| 75 | public function describe($table) |
||
| 90 | 44 | ||
| 91 | /** |
||
| 92 | * Normalize a column definition |
||
| 93 | 49 | * |
|
| 94 | 49 | * The column definition from "DESCRIBE <table>" is to special as useful. Here we normalize it to a more |
|
| 95 | 49 | * ANSI-SQL style. |
|
| 96 | 46 | * |
|
| 97 | 49 | * @param array $rawColumn |
|
| 98 | 49 | * @return array |
|
| 99 | */ |
||
| 100 | 49 | protected function normalizeColumnDefinition($rawColumn) |
|
| 125 | } |
||
| 126 |