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 Labels extends AbstractApi |
||
15 | { |
||
16 | /** |
||
17 | * Base path of board labels api |
||
18 | * @var string |
||
19 | */ |
||
20 | protected $path = 'boards/#id#/labels'; |
||
21 | |||
22 | /** |
||
23 | * Get labels related to a given board |
||
24 | * @link https://trello.com/docs/api/board/#get-1-boards-board-id-labels |
||
25 | * |
||
26 | * @param string $id the board's |
||
27 | * @param array $params optional parameters |
||
28 | * |
||
29 | * @return array |
||
30 | */ |
||
31 | 1 | public function all($id, array $params = array()) |
|
35 | |||
36 | /** |
||
37 | * Get a label related to a given board |
||
38 | * @link https://trello.com/docs/api/board/#get-1-boards-board-id-labels-idlabel |
||
39 | * |
||
40 | * @param string $id the board's id |
||
41 | * @param string $color the label's color |
||
42 | * |
||
43 | * @return array |
||
44 | */ |
||
45 | 2 | View Code Duplication | public function show($id, $color) |
58 | |||
59 | /** |
||
60 | * Set a label's name on a given board and for a given color |
||
61 | * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-blue |
||
62 | * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-green |
||
63 | * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-orange |
||
64 | * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-purple |
||
65 | * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-red |
||
66 | * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-yellow |
||
67 | * |
||
68 | * @param string $id the board's id |
||
69 | * @param string $color the label color to set the name of |
||
70 | * @param string $name |
||
71 | * |
||
72 | * @return array |
||
73 | */ |
||
74 | 2 | View Code Duplication | public function setName($id, $color, $name) |
87 | |||
88 | /** |
||
89 | * Create a list on a given board |
||
90 | * @link https://trello.com/docs/api/board/#post-1-boards-board-id-lists |
||
91 | * |
||
92 | * @param string $id the board's id |
||
93 | * @param string $color the label color to set the name of |
||
94 | * @param string $name |
||
95 | * |
||
96 | * @return array |
||
97 | */ |
||
98 | View Code Duplication | public function create($id, $color, $name) |
|
111 | } |
||
112 |
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.