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 |
||
| 32 | View Code Duplication | class UnitStorageController extends AbstractController |
|
|
1 ignored issue
–
show
|
|||
| 33 | { |
||
| 34 | /** |
||
| 35 | * Lists all UnitStorage entities. |
||
| 36 | * |
||
| 37 | * @Route("/", name="unitstorage") |
||
| 38 | * @Method("GET") |
||
| 39 | * @Template() |
||
| 40 | * |
||
| 41 | * @param \Symfony\Component\HttpFoundation\Request $request Paginate request |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | public function indexAction(Request $request) |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Finds and displays a UnitStorage entity. |
||
| 53 | * |
||
| 54 | * @Route("/{slug}/show", name="unitstorage_show") |
||
| 55 | * @Method("GET") |
||
| 56 | * @Template() |
||
| 57 | * |
||
| 58 | * @param \AppBundle\Entity\Settings\Diverse\UnitStorage $unitstorage UnitStaorage to display |
||
| 59 | * @return array |
||
| 60 | */ |
||
| 61 | public function showAction(UnitStorage $unitstorage) |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Displays a form to create a new UnitStorage entity. |
||
| 70 | * |
||
| 71 | * @Route("/new", name="unitstorage_new") |
||
| 72 | * @Method("GET") |
||
| 73 | * @Template() |
||
| 74 | * |
||
| 75 | * @return array |
||
| 76 | */ |
||
| 77 | public function newAction() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Creates a new UnitStorage entity. |
||
| 91 | * |
||
| 92 | * @Route("/create", name="unitstorage_create") |
||
| 93 | * @Method("POST") |
||
| 94 | * @Template("AppBundle:Settings/Diverse/UnitStorage:new.html.twig") |
||
| 95 | * |
||
| 96 | * @param \Symfony\Component\HttpFoundation\Request $request Form request |
||
| 97 | * @return array |
||
| 98 | */ |
||
| 99 | public function createAction(Request $request) |
||
| 111 | |||
| 112 | /** |
||
| 113 | * Displays a form to edit an existing UnitStorage entity. |
||
| 114 | * |
||
| 115 | * @Route("/{slug}/edit", name="unitstorage_edit") |
||
| 116 | * @Method("GET") |
||
| 117 | * @Template() |
||
| 118 | * |
||
| 119 | * @param \AppBundle\Entity\Settings\Diverse\UnitStorage $unitstorage UnitStorage item to edit |
||
| 120 | * @return array |
||
| 121 | */ |
||
| 122 | public function editAction(UnitStorage $unitstorage) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Edits an existing UnitStorage entity. |
||
| 135 | * |
||
| 136 | * @Route("/{slug}/update", name="unitstorage_update") |
||
| 137 | * @Method("PUT") |
||
| 138 | * @Template("AppBundle:Settings/Diverse/UnitStorage:edit.html.twig") |
||
| 139 | * |
||
| 140 | * @param \AppBndle\Entity\Settings\Diverse\UnitStorage $unitstorage UnitStorage item to update |
||
| 141 | * @param \Symfony\Component\HttpFoundation\Request $request Form request |
||
| 142 | * @return array |
||
| 143 | */ |
||
| 144 | public function updateAction(UnitStorage $unitstorage, Request $request) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * Deletes a UnitStorage entity. |
||
| 158 | * |
||
| 159 | * @Route("/{id}/delete", name="unitstorage_delete", requirements={"id"="\d+"}) |
||
| 160 | * @Method("DELETE") |
||
| 161 | * |
||
| 162 | * @param \AppBundle\Entity\Settings\Diverse\UnitStorage $unitstorage UnitStorage item to delete |
||
| 163 | * @param \Symfony\Component\HttpFoundation\Request $request Form request |
||
| 164 | * @return array |
||
| 165 | */ |
||
| 166 | public function deleteAction(UnitStorage $unitstorage, Request $request) |
||
| 172 | } |
||
| 173 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.