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 |
||
17 | class TbButtonColumn extends CButtonColumn |
||
18 | { |
||
19 | /** |
||
20 | * @var string the view button icon (defaults to 'eye-open'). |
||
21 | */ |
||
22 | public $viewButtonIcon = 'eye-open'; |
||
23 | /** |
||
24 | * @var string the update button icon (defaults to 'pencil'). |
||
25 | */ |
||
26 | public $updateButtonIcon = 'pencil'; |
||
27 | /** |
||
28 | * @var string the delete button icon (defaults to 'trash'). |
||
29 | */ |
||
30 | public $deleteButtonIcon = 'trash'; |
||
31 | |||
32 | /** |
||
33 | * Initializes the default buttons (view, update and delete). |
||
34 | */ |
||
35 | 1 | protected function initDefaultButtons() |
|
46 | |||
47 | /** |
||
48 | * Renders a link button. |
||
49 | * @param string $id the ID of the button |
||
50 | * @param array $button the button configuration which may contain 'label', 'url', 'imageUrl' and 'options' elements. |
||
51 | * @param integer $row the row number (zero-based) |
||
52 | * @param mixed $data the data object associated with the row |
||
53 | */ |
||
54 | protected function renderButton($id, $button, $row, $data) |
||
81 | } |
||
82 |
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.