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 | 6 | * 'sort_field' => 'updated', | |
| 35 | * 'status' => 'published' | ||
| 36 | 6 | * ]; | |
| 37 | 6 | * </code> | |
| 38 | 6 | * | |
| 39 | 6 | * @see http://docs.decision-api.acquia.com/#rules_get | |
| 40 | 6 | * | |
| 41 | 6 | * @param array $options | |
| 42 | 6 | * | |
| 43 | 6 | * @throws \GuzzleHttp\Exception\RequestException | |
| 44 | * | ||
| 45 | * @return \Acquia\LiftClient\Entity\Rule[] | ||
| 46 | 6 | */ | |
| 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 | 6 | * | |
| 70 | * @param array $id | ||
| 71 | 6 | * | |
| 72 | * @throws \GuzzleHttp\Exception\RequestException | ||
| 73 | * | ||
| 74 | 6 | * @return \Acquia\LiftClient\Entity\Rule | |
| 75 | 6 | */ | |
| 76 | 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 | 6 | * | |
| 94 | * @param \Acquia\LiftClient\Entity\Rule $rule | ||
| 95 | 6 | * | |
| 96 | 6 | * @throws \GuzzleHttp\Exception\RequestException | |
| 97 | 6 | * | |
| 98 | 6 | * @return \Acquia\LiftClient\Entity\Rule | |
| 99 | */ | ||
| 100 | 3 | 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 | 6 | * | |
| 115 | * @param string $id | ||
| 116 | 6 | * | |
| 117 | 6 | * @throws \GuzzleHttp\Exception\RequestException | |
| 118 | * | ||
| 119 | 3 | * @return bool | |
| 120 | */ | ||
| 121 | public function delete($id) | ||
| 128 | } | ||
| 129 |