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 |
||
| 8 | class RuleManager extends ManagerBase |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Get a list of Rules. |
||
| 12 | * |
||
| 13 | * Example of how to structure the $options parameter: |
||
| 14 | * <code> |
||
| 15 | * $options = [ |
||
| 16 | * 'visible_on_page' => 'node/1/*', |
||
| 17 | * 'prefetch' => true, |
||
| 18 | * 'sort' => 'asc', |
||
| 19 | * 'start' => 0, |
||
| 20 | * 'rows' => 0, |
||
| 21 | * 'sort_field' => 'updated', |
||
| 22 | * 'status' => 'published' |
||
| 23 | * ]; |
||
| 24 | * </code> |
||
| 25 | * |
||
| 26 | * @see http://docs.decision-api.acquia.com/#rules_get |
||
| 27 | * |
||
| 28 | * @param array $options |
||
| 29 | * |
||
| 30 | * @throws \GuzzleHttp\Exception\RequestException |
||
| 31 | * |
||
| 32 | * @return \Acquia\LiftClient\Entity\Rule[] |
||
| 33 | */ |
||
| 34 | public function query($options = []) |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Get a specific rule. |
||
| 60 | * |
||
| 61 | * @see http://docs.decision-api.acquia.com/#rules__ruleId__get |
||
| 62 | * |
||
| 63 | * @param array $id |
||
| 64 | * |
||
| 65 | * @throws \GuzzleHttp\Exception\RequestException |
||
| 66 | * |
||
| 67 | * @return \Acquia\LiftClient\Entity\Rule |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function get($id) |
|
| 79 | |||
| 80 | /** |
||
| 81 | * Add or update a rule. |
||
| 82 | * |
||
| 83 | * To Update a rule, use a Rule object with an existing identifier. |
||
| 84 | * |
||
| 85 | * @see http://docs.decision-api.acquia.com/#rules_post |
||
| 86 | * |
||
| 87 | * @param \Acquia\LiftClient\Entity\Rule $rule |
||
| 88 | * |
||
| 89 | * @throws \GuzzleHttp\Exception\RequestException |
||
| 90 | * |
||
| 91 | * @return \Acquia\LiftClient\Entity\Rule |
||
| 92 | */ |
||
| 93 | View Code Duplication | public function add(Rule $rule) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * Deletes a rule by ID. |
||
| 105 | * |
||
| 106 | * @see http://docs.decision-api.acquia.com/#rules__ruleId__delete |
||
| 107 | * |
||
| 108 | * @param string $id |
||
| 109 | * |
||
| 110 | * @throws \GuzzleHttp\Exception\RequestException |
||
| 111 | * |
||
| 112 | * @return bool |
||
| 113 | */ |
||
| 114 | public function delete($id) |
||
| 121 | } |
||
| 122 |