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 namespace Bedard\Shop\Api; |
||
| 8 | class Cart extends ApiController |
||
| 9 | { |
||
| 10 | /** |
||
| 11 | * Add an inventory to the cart. |
||
| 12 | * |
||
| 13 | * @param CartRepository $repository |
||
| 14 | */ |
||
| 15 | public function add(CartRepository $repository) |
||
| 28 | |||
| 29 | /** |
||
| 30 | * Apply a promotion to the cart. |
||
| 31 | * |
||
| 32 | * @param CartRepository $repository |
||
| 33 | * @return [type] |
||
|
|
|||
| 34 | */ |
||
| 35 | View Code Duplication | public function applyPromotion(CartRepository $repository) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * Determine if a cart exists or not. |
||
| 50 | * |
||
| 51 | * @param CartRepository $repository |
||
| 52 | * @return bool |
||
| 53 | */ |
||
| 54 | View Code Duplication | public function exists(CartRepository $repository) |
|
| 64 | |||
| 65 | /** |
||
| 66 | * Show the current cart. |
||
| 67 | * |
||
| 68 | * @param \Bedard\Shop\Repositories\CartRepository $repository |
||
| 69 | * @return \Bedard\Shop\Models\Cart |
||
| 70 | */ |
||
| 71 | View Code Duplication | public function index(CartRepository $repository) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Delete an item from the cart. |
||
| 84 | * |
||
| 85 | * @param CartRepository $repository |
||
| 86 | * @param int $inventoryId |
||
| 87 | * @return \Bedard\Shop\Models\Cart |
||
| 88 | */ |
||
| 89 | public function deleteItem(CartRepository $repository, $inventoryId) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Create a new cart. |
||
| 104 | * |
||
| 105 | * @param \Bedard\Shop\Repositories\CartRepository $repository |
||
| 106 | * @return \Bedard\Shop\Models\Cart |
||
| 107 | */ |
||
| 108 | public function store(CartRepository $repository) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Update an item in the cart. |
||
| 122 | * |
||
| 123 | * @param CartRepository $repository |
||
| 124 | * @return [type] |
||
| 125 | */ |
||
| 126 | View Code Duplication | public function updateItem(CartRepository $repository, $itemId) |
|
| 138 | } |
||
| 139 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.