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 |
||
| 10 | class Products extends Client implements ProductInterface, ProductsInterface |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * Get product |
||
| 14 | * |
||
| 15 | * @param int $productCode |
||
| 16 | * |
||
| 17 | * @return QueryInterface |
||
| 18 | */ |
||
| 19 | public function __invoke(string $productCode): ProductInterface |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Create product |
||
| 32 | * |
||
| 33 | * @return \Rezdy\Interfaces\QueryInterface |
||
| 34 | */ |
||
| 35 | public function create(): QueryInterface |
||
| 43 | |||
| 44 | /** |
||
| 45 | * Update product |
||
| 46 | * |
||
| 47 | * @return \Rezdy\Interfaces\QueryInterface |
||
| 48 | */ |
||
| 49 | public function update(): QueryInterface |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Delete product |
||
| 60 | * |
||
| 61 | * @return \Rezdy\Interfaces\QueryInterface |
||
| 62 | */ |
||
| 63 | public function delete(): QueryInterface |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Search products |
||
| 74 | * |
||
| 75 | * @return \Rezdy\Interfaces\QueryInterface |
||
| 76 | */ |
||
| 77 | public function search(): QueryInterface |
||
| 85 | |||
| 86 | /** |
||
| 87 | * Search marketplace products |
||
| 88 | * |
||
| 89 | * @return \Rezdy\Interfaces\QueryInterface |
||
| 90 | */ |
||
| 91 | public function searchMarketplace(): QueryInterface |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Get product pickups |
||
| 102 | * |
||
| 103 | * @return \Rezdy\Interfaces\QueryInterface |
||
| 104 | */ |
||
| 105 | public function getPickups(): QueryInterface |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Add product image |
||
| 116 | * |
||
| 117 | * @return \Rezdy\Interfaces\QueryInterface |
||
| 118 | */ |
||
| 119 | public function createImage(): QueryInterface |
||
| 127 | |||
| 128 | /** |
||
| 129 | * Remove product Image |
||
| 130 | * |
||
| 131 | * @param string $mediaId |
||
| 132 | * |
||
| 133 | * @return \Rezdy\Interfaces\QueryInterface |
||
| 134 | */ |
||
| 135 | public function getImage(string $mediaId): QueryInterface |
||
| 143 | |||
| 144 | } |
||
| 145 |
Since your code implements the magic setter
_set, this function will be called for any write access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write 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.