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 |
||
| 16 | class SimpleAction extends AbstractAction implements RowDataAwareInterface |
||
| 17 | { |
||
| 18 | |||
| 19 | use RowDataAwareTrait; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @return string |
||
| 23 | */ |
||
| 24 | public function getUrl() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @param array $matches |
||
| 41 | * @return mixed|string |
||
| 42 | */ |
||
| 43 | View Code Duplication | protected function replaceCallback($matches) |
|
| 59 | |||
| 60 | /** |
||
| 61 | * @return bool|mixed |
||
| 62 | */ |
||
| 63 | View Code Duplication | public function validate() |
|
| 71 | } |
||
| 72 |
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.