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 | View Code Duplication | class Members extends AbstractApi |
|
|
|||
16 | { |
||
17 | /** |
||
18 | * Base path of board members api |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $path = 'organizations/#id#/members'; |
||
22 | |||
23 | /** |
||
24 | * Get a given board's members |
||
25 | * @link https://trello.com/docs/api/board/#get-1-boards-board-id-members |
||
26 | * |
||
27 | * @param string $id the board's id |
||
28 | * @param array $params optional parameters |
||
29 | * |
||
30 | * @return array |
||
31 | */ |
||
32 | 1 | public function all($id, array $params = array()) |
|
36 | |||
37 | /** |
||
38 | * Filter members related to a given board |
||
39 | * @link https://trello.com/docs/api/board/#get-1-boards-board-id-members-filter |
||
40 | * |
||
41 | * @param string $id the board's id |
||
42 | * @param string|array $filter array of / one of 'none', 'normal', 'admins', 'owners', 'all' |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | 3 | public function filter($id, $filter = 'all') |
|
53 | } |
||
54 |
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.