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 |
||
| 14 | class DatabaseDriver implements DriverInterface |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var array |
||
| 18 | */ |
||
| 19 | protected $configuration = []; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var string |
||
| 23 | */ |
||
| 24 | protected $driver = ''; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param string $driver |
||
| 28 | * @param array $configuration |
||
| 29 | */ |
||
| 30 | 18 | public function __construct($driver, $configuration = []) |
|
| 35 | |||
| 36 | /** |
||
| 37 | * Gets the specified driver from the specified database connection. |
||
| 38 | * |
||
| 39 | * @param string $driverName |
||
| 40 | * @param array $configuration |
||
| 41 | * @return \Rougin\Describe\Driver\DriverInterface|null |
||
| 42 | */ |
||
| 43 | 18 | public function getDriver($driverName, $configuration = []) |
|
| 63 | |||
| 64 | /** |
||
| 65 | * Returns the result. |
||
| 66 | * |
||
| 67 | * @return array |
||
| 68 | */ |
||
| 69 | 12 | public function getTable($table) |
|
| 75 | |||
| 76 | /** |
||
| 77 | * Shows the list of tables. |
||
| 78 | * |
||
| 79 | * @return array |
||
| 80 | */ |
||
| 81 | 6 | public function showTables() |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Parses the configuration into separate variables. |
||
| 90 | * |
||
| 91 | * @param array $configuration |
||
| 92 | * @return array |
||
| 93 | */ |
||
| 94 | 18 | protected function parseConfiguration(array $configuration) |
|
| 120 | } |
||
| 121 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.