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 |
||
| 27 | class EditController extends Controller |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Main controller action |
||
| 31 | * |
||
| 32 | * @param Request $request |
||
| 33 | * @param $source |
||
| 34 | * @param $rateType |
||
| 35 | * @param $currencyCode |
||
| 36 | * @param \DateTime $date |
||
| 37 | * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response|\Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
| 38 | */ |
||
| 39 | public function indexAction(Request $request, $source, $rateType, $currencyCode, \DateTime $date) |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Handle form submission. |
||
| 69 | * |
||
| 70 | * @param Form $form |
||
| 71 | * @param Request $request |
||
| 72 | * @param RateInterface $rate |
||
|
|
|||
| 73 | * |
||
| 74 | * @return bool TRUE if successful |
||
| 75 | */ |
||
| 76 | protected function handleForm(Form $form, Request $request, RateInterface $exchangeRate) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Get FQCN of FormType form. |
||
| 99 | * |
||
| 100 | * @return string |
||
| 101 | */ |
||
| 102 | protected function getFormType() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Get form. |
||
| 109 | * |
||
| 110 | * @return Form |
||
| 111 | */ |
||
| 112 | protected function getForm(RateInterface $rate) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Save rate. |
||
| 119 | * |
||
| 120 | * @param Rate $rate |
||
| 121 | * @return TRUE if successful. |
||
| 122 | */ |
||
| 123 | View Code Duplication | protected function save(Rate $rate) |
|
| 134 | |||
| 135 | /** |
||
| 136 | * Redirect after success. |
||
| 137 | * |
||
| 138 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
| 139 | */ |
||
| 140 | protected function redirectAfterSuccess() |
||
| 144 | } |
||
| 145 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.