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 |
||
| 18 | View Code Duplication | class Groups extends Api |
|
|
|
|||
| 19 | { |
||
| 20 | /** |
||
| 21 | * List rule groups (permission needed: #zone:read) |
||
| 22 | * Search, list, and sort rule groups contained within a package |
||
| 23 | * |
||
| 24 | * @param string $zone_identifier |
||
| 25 | * @param string $package_identifier |
||
| 26 | * @param string|null $name Name of the firewall rule group |
||
| 27 | * @param string|null $mode Whether or not the rules contained within this group are configurable/usable |
||
| 28 | * @param int|null $rules_count How many rules are contained within this group |
||
| 29 | * @param int|null $page Page number of paginated results |
||
| 30 | * @param int|null $per_page Number of groups per page |
||
| 31 | * @param string|null $order Field to order groups by |
||
| 32 | * @param string|null $direction Direction to order groups |
||
| 33 | * @param string|null $match Whether to match all search requirements or at least one (any) |
||
| 34 | */ |
||
| 35 | public function groups($zone_identifier, $package_identifier, $name = null, $mode = null, $rules_count = null, $page = null, $per_page = null, $order = null, $direction = null, $match = null) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Rule group info (permission needed: #zone:read) |
||
| 53 | * Get a single rule group |
||
| 54 | * |
||
| 55 | * @param string $zone_identifier |
||
| 56 | * @param string $package_identifier |
||
| 57 | * @param string $identifier |
||
| 58 | */ |
||
| 59 | public function info($zone_identifier, $package_identifier, $identifier) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Update Rule group (permission needed: #zone:edit) |
||
| 66 | * Update the state of a rule group |
||
| 67 | * |
||
| 68 | * @param string $zone_identifier |
||
| 69 | * @param string $package_identifier |
||
| 70 | * @param string $identifier |
||
| 71 | * @param string|null $mode Whether or not the rules contained within this group are configurable/usable |
||
| 72 | */ |
||
| 73 | public function update($zone_identifier, $package_identifier, $identifier, $mode = null) |
||
| 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.