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 |
||
| 18 | class AuditDiff |
||
| 19 | { |
||
| 20 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 21 | /** |
||
| 22 | * The metadata (additional) audit columns (as stored in the config file). |
||
| 23 | * |
||
| 24 | * @var TableColumnsMetadata |
||
| 25 | */ |
||
| 26 | private $auditColumnsMetadata; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The names of all tables in audit schema. |
||
| 30 | * |
||
| 31 | * @var array |
||
| 32 | */ |
||
| 33 | private $auditSchemaTables; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * The content of the configuration file. |
||
| 37 | * |
||
| 38 | * @var array |
||
| 39 | */ |
||
| 40 | private $config; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * The names of all tables in data schema. |
||
| 44 | * |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | private $dataSchemaTables; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Array with columns for each table. |
||
| 51 | * array [ |
||
| 52 | * table_name [ |
||
| 53 | * column [ |
||
| 54 | * data table type, |
||
| 55 | * audit table type |
||
| 56 | * ], |
||
| 57 | * ... |
||
| 58 | * ] |
||
| 59 | * ] |
||
| 60 | * |
||
| 61 | * @var array[] |
||
| 62 | */ |
||
| 63 | private $diffColumns; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * If set all tables and columns are shown. |
||
| 67 | * |
||
| 68 | * @var boolean |
||
| 69 | */ |
||
| 70 | private $full; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * The Input interface. |
||
| 74 | * |
||
| 75 | * @var InputInterface |
||
| 76 | */ |
||
| 77 | private $input; |
||
| 78 | |||
| 79 | /** |
||
| 80 | * The Output decorator. |
||
| 81 | * |
||
| 82 | * @var StratumStyle |
||
| 83 | */ |
||
| 84 | private $io; |
||
| 85 | |||
| 86 | /** |
||
| 87 | * The Output interface. |
||
| 88 | * |
||
| 89 | * @var OutputInterface |
||
| 90 | */ |
||
| 91 | private $output; |
||
| 92 | |||
| 93 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 94 | /** |
||
| 95 | * Object constructor. |
||
| 96 | * |
||
| 97 | * @param array[] $config The content of the configuration file. |
||
| 98 | * @param StratumStyle $io The Output decorator. |
||
| 99 | * @param InputInterface $input |
||
| 100 | * @param OutputInterface $output |
||
| 101 | */ |
||
| 102 | public function __construct(&$config, $io, $input, $output) |
||
| 109 | |||
| 110 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 111 | /** |
||
| 112 | * The main method: executes the auditing actions for tables. |
||
| 113 | * |
||
| 114 | * @return int The exit status. |
||
|
|
|||
| 115 | */ |
||
| 116 | public function main() |
||
| 144 | |||
| 145 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 146 | /** |
||
| 147 | * Writes the difference between the audit tables and metadata tables to the output. |
||
| 148 | */ |
||
| 149 | private function diffTables() |
||
| 164 | |||
| 165 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 166 | /** |
||
| 167 | * Computes the difference between data and audit tables. |
||
| 168 | */ |
||
| 169 | private function getDiff() |
||
| 187 | |||
| 188 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 189 | /** |
||
| 190 | * Getting list of all tables from information_schema of database from config file. |
||
| 191 | */ |
||
| 192 | private function listOfTables() |
||
| 198 | |||
| 199 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 200 | /** |
||
| 201 | * Writes the difference between the audit and data tables to the output. |
||
| 202 | */ |
||
| 203 | private function printDiff() |
||
| 250 | |||
| 251 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 252 | /** |
||
| 253 | * Resolves the canonical column types of the audit table columns. |
||
| 254 | */ |
||
| 255 | View Code Duplication | private function resolveCanonicalAuditColumns() |
|
| 285 | |||
| 286 | //-------------------------------------------------------------------------------------------------------------------- |
||
| 287 | } |
||
| 288 | |||
| 290 |
This check compares the return type specified in the
@returnannotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.