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 |
||
| 11 | class InvolvedRepository extends Repository |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * @return Involved |
||
| 15 | */ |
||
| 16 | public function getModel() |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Involve the product offer |
||
| 23 | * |
||
| 24 | * @param array $data |
||
| 25 | * @param Product $product |
||
| 26 | * @return Involved |
||
| 27 | */ |
||
| 28 | |||
| 29 | public function create(array $data, $product) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Update involve status. |
||
| 45 | * |
||
| 46 | * @param Involved $involve |
||
| 47 | * @param array $data |
||
| 48 | * @return $this |
||
| 49 | */ |
||
| 50 | public function update(Involved $involve, array $data) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Check if auth-cate user is involved to this product. |
||
| 64 | * |
||
| 65 | * @param Product $product |
||
| 66 | * @return bool |
||
| 67 | */ |
||
| 68 | public function checkIfAuthInvolved(Product $product) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @param array $data |
||
| 77 | * @param $product |
||
| 78 | * @return Involved|InvolvedRepository |
||
| 79 | */ |
||
| 80 | public function createOrUpdate(array $data, $product) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @param $product |
||
| 90 | * @param null $user |
||
| 91 | * @param bool $active |
||
| 92 | * @return mixed |
||
| 93 | */ |
||
| 94 | View Code Duplication | public function getModelByUserAndProduct($product, $user = null, $active = true) |
|
| 102 | |||
| 103 | /** |
||
| 104 | * @param $product |
||
| 105 | * @param bool $active |
||
| 106 | * @return mixed |
||
| 107 | */ |
||
| 108 | View Code Duplication | public function getModelsByUserAndProduct($product, $active = true) |
|
| 116 | |||
| 117 | /** |
||
| 118 | * Count rules. |
||
| 119 | * |
||
| 120 | * @return string |
||
| 121 | */ |
||
| 122 | public function countRules() |
||
| 126 | |||
| 127 | /** |
||
| 128 | * @param $product |
||
| 129 | * @return int |
||
| 130 | */ |
||
| 131 | public function getInvolveTimesProduct($product) |
||
| 135 | |||
| 136 | public function getCountSelled($id) |
||
| 143 | |||
| 144 | public function getInvolvedProductforUser() { |
||
| 153 | |||
| 154 | } |
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.