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 |
||
| 14 | class SurveyController extends Controller |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @Route("/surveys", name="list_surveys") |
||
| 18 | * @Method("GET") |
||
| 19 | * |
||
| 20 | * @return JsonResponse |
||
| 21 | */ |
||
| 22 | 2 | public function listAction() |
|
| 23 | { |
||
| 24 | 2 | $surveys = $this->getDoctrine() |
|
| 25 | 2 | ->getRepository(Survey::class) |
|
| 26 | 2 | ->findSurveyByUser($this->getUser()); |
|
| 27 | 2 | $json = $this->get('serializer')->normalize($surveys, null, array('groups' => array('list'))); |
|
| 28 | |||
| 29 | 2 | return $this->json(['surveys' => $json], 200); |
|
| 30 | } |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param int $id |
||
| 34 | * @Route("/surveys/{id}", requirements={"id": "\d+"}, name="show_survey") |
||
| 35 | * @Method("GET") |
||
| 36 | * |
||
| 37 | * @return JsonResponse |
||
| 38 | */ |
||
| 39 | public function showAction($id) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @param Request $request, int $id |
||
|
|
|||
| 53 | * @Route("/surveys/{id}", requirements={"id": "\d+"}, name="edit_survey") |
||
| 54 | * @Method("PUT") |
||
| 55 | * |
||
| 56 | * @return JsonResponse |
||
| 57 | */ |
||
| 58 | 1 | public function editAction(Request $request, $id) |
|
| 96 | } |
||
| 97 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$irelandis not defined by the methodfinale(...).The most likely cause is that the parameter was changed, but the annotation was not.