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 |
||
| 21 | class Manager implements ManagerInterface |
||
| 22 | { |
||
| 23 | /** |
||
| 24 | * Database handler |
||
| 25 | * @var PDO |
||
| 26 | */ |
||
| 27 | private $pdo; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Manager constructor. |
||
| 31 | * |
||
| 32 | * @param PDO $pdo |
||
| 33 | * @throws DatabaseException |
||
| 34 | */ |
||
| 35 | public function __construct(PDO $pdo) |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Clean the delay table |
||
| 42 | * |
||
| 43 | * @param int $delay - in seconds |
||
| 44 | * @return bool |
||
| 45 | */ |
||
| 46 | public function clean($delay) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Top X wait time |
||
| 59 | * |
||
| 60 | * @param int $limit |
||
| 61 | * @param int $min |
||
| 62 | * @return array |
||
| 63 | */ |
||
| 64 | public function getTopWaitTimes($limit, $min) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Debug - Get raw data |
||
| 89 | * |
||
| 90 | * @param string $base |
||
| 91 | * @return array |
||
| 92 | */ |
||
| 93 | View Code Duplication | public function debug($base) |
|
| 105 | } |
||
| 106 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.