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 RdsActionInspector extends AbstractActionInspector |
||
15 | { |
||
16 | const TABLE_NAME = 'scheduler_action_inspector'; |
||
17 | const COLUMN_ID = 'id'; |
||
18 | const COLUMN_REPORT = 'report'; |
||
19 | const COLUMN_STATE = 'state'; |
||
20 | |||
21 | /** @var \Doctrine\DBAL\Connection */ |
||
22 | private $connection; |
||
23 | |||
24 | /** |
||
25 | * RdsActionInspector constructor. |
||
26 | * @param \Doctrine\DBAL\Connection $connection |
||
27 | */ |
||
28 | 1 | public function __construct(\Doctrine\DBAL\Connection $connection) |
|
32 | |||
33 | /** |
||
34 | * @param ActionInterface $action |
||
35 | * @return boolean returns `false` if action is already exists in this state in the log |
||
36 | * @throws SchedulerException |
||
37 | */ |
||
38 | 1 | public function update(ActionInterface $action) |
|
68 | |||
69 | /** |
||
70 | * @param $actionId |
||
71 | * @return \Doctrine\DBAL\Query\QueryBuilder |
||
72 | */ |
||
73 | 1 | private function getSelectQuery($actionId) |
|
81 | |||
82 | /** |
||
83 | * @param $actionState |
||
84 | * @param $actionId |
||
85 | * @return \Doctrine\DBAL\Query\QueryBuilder |
||
86 | */ |
||
87 | 1 | View Code Duplication | private function getUpdateQuery($actionState, $actionId) |
96 | |||
97 | /** |
||
98 | * @param $actionState |
||
99 | * @param $actionId |
||
100 | * @return \Doctrine\DBAL\Query\QueryBuilder |
||
101 | */ |
||
102 | 1 | View Code Duplication | private function getInsertQuery($actionState, $actionId) |
113 | |||
114 | /** |
||
115 | * @return \Doctrine\DBAL\Connection |
||
116 | */ |
||
117 | 1 | private function getConnection() |
|
121 | |||
122 | /** |
||
123 | * @param \Doctrine\DBAL\Connection $connection |
||
124 | * @throws \Doctrine\DBAL\DBALException |
||
125 | */ |
||
126 | 3 | public static function initDb(\Doctrine\DBAL\Connection $connection) |
|
142 | |||
143 | 2 | public static function dropDb(\Doctrine\DBAL\Connection $connection) |
|
154 | } |
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.