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 |
||
15 | class ActionCallback extends Action |
||
16 | { |
||
17 | |||
18 | /** |
||
19 | * @var callable |
||
20 | */ |
||
21 | public $onClick = []; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $key; |
||
27 | |||
28 | |||
29 | /** |
||
30 | * @param DataGrid $grid |
||
31 | * @param string $key |
||
32 | * @param string $name |
||
33 | * @param array $params |
||
34 | */ |
||
35 | View Code Duplication | public function __construct(DataGrid $grid, $key, $name, $params) |
|
44 | |||
45 | |||
46 | /** |
||
47 | * Create link to datagrid::handleActionCallback() to fire custom callback |
||
48 | * @param Row $row |
||
49 | * @return string |
||
50 | * @throws DataGridHasToBeAttachedToPresenterComponentException |
||
51 | */ |
||
52 | protected function createLink(Row $row) |
||
58 | |||
59 | } |
||
60 |
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.