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 | protected $path = 'cards/#id#/labels'; |
||
17 | |||
18 | /** |
||
19 | * Set a given card's labels |
||
20 | * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-labels |
||
21 | * |
||
22 | * @param string $id the card's id or short link |
||
23 | * @param array $labels the labels |
||
24 | * |
||
25 | * @return array card info |
||
26 | * |
||
27 | * @throws InvalidArgumentException If a label does not exist |
||
28 | */ |
||
29 | 2 | public function set($id, array $labels) |
|
41 | |||
42 | /** |
||
43 | * Set a given card's label by labelId |
||
44 | * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-labels |
||
45 | * |
||
46 | * @param string $id the card's id or short link |
||
47 | * @param string $labelId the label id |
||
48 | * |
||
49 | * @return array card info |
||
50 | * |
||
51 | * @throws InvalidArgumentException If a label does not exist |
||
52 | */ |
||
53 | 2 | public function setById($id, $labelId) |
|
60 | |||
61 | /** |
||
62 | * Remove a given label from a given card |
||
63 | * @link https://trello.com/docs/api/card/#delete-1-cards-card-id-or-shortlink-labels-color |
||
64 | * |
||
65 | * @param string $id the card's id or short link |
||
66 | * @param string $label the label to remove |
||
67 | * |
||
68 | * @return array card info |
||
69 | * |
||
70 | * @throws InvalidArgumentException If a label does not exist |
||
71 | */ |
||
72 | View Code Duplication | public function remove($id, $label) |
|
80 | |||
81 | /** |
||
82 | * Remove a given label from a given card based on the label id |
||
83 | * @link https://developers.trello.com/advanced-reference/card#delete-1-cards-card-id-or-shortlink-idlabels-idlabel |
||
84 | * |
||
85 | * @param string $id the card's id or short link |
||
86 | * @param string $labelId the label id to remove |
||
87 | * |
||
88 | * @return array card info |
||
89 | * |
||
90 | * @throws InvalidArgumentException If a label does not exist |
||
91 | */ |
||
92 | public function removeById($id, $labelId) |
||
97 | } |
||
98 |
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.