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 |
||
| 13 | View Code Duplication | class Cards extends AbstractApi |
|
|
|
|||
| 14 | { |
||
| 15 | protected $path = 'members/#id#/cards'; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Get cards related to a given list |
||
| 19 | * @link https://trello.com/docs/api/member/#get-1-members-idmember-or-username-cards |
||
| 20 | * |
||
| 21 | * @param string $id the member's id or username |
||
| 22 | * @param array $params optional parameters |
||
| 23 | * |
||
| 24 | * @return array |
||
| 25 | */ |
||
| 26 | 1 | public function all($id, array $params = array()) |
|
| 30 | |||
| 31 | /** |
||
| 32 | * Filter cards related to a given list |
||
| 33 | * @link https://trello.com/docs/api/list/#get-1-lists-idlist-cards-filter |
||
| 34 | * |
||
| 35 | * @param string $id the list's id |
||
| 36 | * @param array $filter one of 'none', 'visible', 'open', 'closed', 'all' |
||
| 37 | * |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | 3 | public function filter($id, $filter = 'all') |
|
| 47 | } |
||
| 48 |
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.