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 | * {@inheritdoc} |
||
| 12 | */ |
||
| 13 | protected $queryParameters = [ |
||
| 14 | 'visible_on_page' => null, |
||
| 15 | 'prefetch' => null, |
||
| 16 | 'sort' => null, |
||
| 17 | 'start' => null, |
||
| 18 | 'rows' => null, |
||
| 19 | 'sort_field' => null, |
||
| 20 | 'status' => null, |
||
| 21 | ]; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Get a list of Rules. |
||
| 25 | * |
||
| 26 | * Example of how to structure the $options parameter: |
||
| 27 | * <code> |
||
| 28 | * $options = [ |
||
| 29 | * 'visible_on_page' => 'node/1/*', |
||
| 30 | * 'prefetch' => true, |
||
| 31 | * 'sort' => 'asc', |
||
| 32 | * 'start' => 0, |
||
| 33 | * 'rows' => 10, |
||
| 34 | * 'sort_field' => 'updated', |
||
| 35 | * 'status' => 'published' |
||
| 36 | * ]; |
||
| 37 | * </code> |
||
| 38 | * |
||
| 39 | * @see http://docs.decision-api.acquia.com/#rules_get |
||
| 40 | * |
||
| 41 | * @param array $options |
||
| 42 | * |
||
| 43 | * @throws \GuzzleHttp\Exception\RequestException |
||
| 44 | * |
||
| 45 | * @return \Acquia\LiftClient\Entity\Rule[] |
||
| 46 | */ |
||
| 47 | 6 | View Code Duplication | public function query($options = []) |
| 64 | |||
| 65 | /** |
||
| 66 | * Get a specific rule. |
||
| 67 | * |
||
| 68 | * @see http://docs.decision-api.acquia.com/#rules__ruleId__get |
||
| 69 | * |
||
| 70 | * @param array $id |
||
| 71 | * |
||
| 72 | * @throws \GuzzleHttp\Exception\RequestException |
||
| 73 | * |
||
| 74 | * @return \Acquia\LiftClient\Entity\Rule |
||
| 75 | */ |
||
| 76 | 6 | View Code Duplication | public function get($id) |
| 86 | |||
| 87 | /** |
||
| 88 | * Add or update a rule. |
||
| 89 | * |
||
| 90 | * To Update a rule, use a Rule object with an existing identifier. |
||
| 91 | * |
||
| 92 | * @see http://docs.decision-api.acquia.com/#rules_post |
||
| 93 | * |
||
| 94 | * @param \Acquia\LiftClient\Entity\Rule $rule |
||
| 95 | * |
||
| 96 | * @throws \GuzzleHttp\Exception\RequestException |
||
| 97 | * |
||
| 98 | * @return \Acquia\LiftClient\Entity\Rule |
||
| 99 | */ |
||
| 100 | 6 | View Code Duplication | public function add(Rule $rule) |
| 109 | |||
| 110 | /** |
||
| 111 | * Deletes a rule by ID. |
||
| 112 | * |
||
| 113 | * @see http://docs.decision-api.acquia.com/#rules__ruleId__delete |
||
| 114 | * |
||
| 115 | * @param string $id |
||
| 116 | * |
||
| 117 | * @throws \GuzzleHttp\Exception\RequestException |
||
| 118 | * |
||
| 119 | * @return bool |
||
| 120 | */ |
||
| 121 | 6 | public function delete($id) |
|
| 128 | } |
||
| 129 |