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 |
||
| 19 | class AuditDiff |
||
| 20 | { |
||
| 21 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 22 | /** |
||
| 23 | * The metadata (additional) audit columns (as stored in the config file). |
||
| 24 | * |
||
| 25 | * @var TableColumnsMetadata |
||
| 26 | */ |
||
| 27 | private $auditColumnsMetadata; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * The names of all tables in audit schema. |
||
| 31 | * |
||
| 32 | * @var array |
||
| 33 | */ |
||
| 34 | private $auditSchemaTables; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * The content of the configuration file. |
||
| 38 | * |
||
| 39 | * @var array |
||
| 40 | */ |
||
| 41 | private $config; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Config metadata columns. |
||
| 45 | * |
||
| 46 | * @var array |
||
| 47 | */ |
||
| 48 | private $configMetadata; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * The names of all tables in data schema. |
||
| 52 | * |
||
| 53 | * @var array |
||
| 54 | */ |
||
| 55 | private $dataSchemaTables; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Array with columns for each table. |
||
| 59 | * array [ |
||
| 60 | * table_name [ |
||
| 61 | * column [ |
||
| 62 | * data table type, |
||
| 63 | * audit table type |
||
| 64 | * ], |
||
| 65 | * ... |
||
| 66 | * ] |
||
| 67 | * ] |
||
| 68 | * |
||
| 69 | * @var array[] |
||
| 70 | */ |
||
| 71 | private $diffColumns; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * If set all tables and columns are shown. |
||
| 75 | * |
||
| 76 | * @var boolean |
||
| 77 | */ |
||
| 78 | private $full; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The Input interface. |
||
| 82 | * |
||
| 83 | * @var InputInterface |
||
| 84 | */ |
||
| 85 | private $input; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * The Output decorator. |
||
| 89 | * |
||
| 90 | * @var StratumStyle |
||
| 91 | */ |
||
| 92 | private $io; |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The Output interface. |
||
| 96 | * |
||
| 97 | * @var OutputInterface |
||
| 98 | */ |
||
| 99 | private $output; |
||
| 100 | |||
| 101 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 102 | /** |
||
| 103 | * Object constructor. |
||
| 104 | * |
||
| 105 | * @param array[] $config The content of the configuration file. |
||
| 106 | * @param array[] $configMetadata The content of the metadata file. |
||
| 107 | * @param StratumStyle $io The Output decorator. |
||
| 108 | * @param InputInterface $input |
||
| 109 | * @param OutputInterface $output |
||
| 110 | */ |
||
| 111 | public function __construct(&$config, $configMetadata, $io, $input, $output) |
||
| 119 | |||
| 120 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 121 | /** |
||
| 122 | * The main method: executes the auditing actions for tables. |
||
| 123 | */ |
||
| 124 | public function main() |
||
| 152 | |||
| 153 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 154 | /** |
||
| 155 | * Writes the difference between the audit tables and metadata tables to the output. |
||
| 156 | */ |
||
| 157 | private function diffTables() |
||
| 176 | |||
| 177 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 178 | /** |
||
| 179 | * Computes the difference between data and audit tables. |
||
| 180 | */ |
||
| 181 | private function getDiff() |
||
| 199 | |||
| 200 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 201 | /** |
||
| 202 | * Getting list of all tables from information_schema of database from config file. |
||
| 203 | */ |
||
| 204 | private function listOfTables() |
||
| 210 | |||
| 211 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 212 | /** |
||
| 213 | * Writes the difference between the audit and data tables to the output. |
||
| 214 | */ |
||
| 215 | private function printDiff() |
||
| 262 | |||
| 263 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 264 | /** |
||
| 265 | * Print missing or obsolete tables; |
||
| 266 | * |
||
| 267 | * @param string $tableType Missing or obsolete. |
||
| 268 | * @param array[] $tables Table names array. |
||
| 269 | */ |
||
| 270 | private function printMissObsoleteTables($tableType, $tables) |
||
| 295 | |||
| 296 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 297 | /** |
||
| 298 | * Resolves the canonical column types of the audit table columns. |
||
| 299 | */ |
||
| 300 | View Code Duplication | private function resolveCanonicalAuditColumns() |
|
| 330 | |||
| 331 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 332 | } |
||
| 333 | |||
| 335 |
Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.