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 |
||
| 31 | class MaterialController extends AbstractController |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * Lists all Material entities. |
||
| 35 | * |
||
| 36 | * @Route("/", name="material") |
||
| 37 | * @Method("GET") |
||
| 38 | * @Template() |
||
| 39 | */ |
||
| 40 | public function indexAction(Request $request) |
||
| 46 | |||
| 47 | /** |
||
| 48 | * Finds and displays a Material entity. |
||
| 49 | * |
||
| 50 | * @Route("/{slug}/show", name="material_show") |
||
| 51 | * @Method("GET") |
||
| 52 | * @Template() |
||
| 53 | */ |
||
| 54 | public function showAction(Material $material) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Displays a form to create a new Material entity. |
||
| 63 | * |
||
| 64 | * @Route("/new", name="material_new") |
||
| 65 | * @Method("GET") |
||
| 66 | * @Template() |
||
| 67 | */ |
||
| 68 | View Code Duplication | public function newAction() |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Creates a new Material entity. |
||
| 84 | * |
||
| 85 | * @Route("/admin/create", name="material_create") |
||
| 86 | * @Method("POST") |
||
| 87 | * @Template("AppBundle:Settings\Diverse\Material:new.html.twig") |
||
| 88 | */ |
||
| 89 | public function createAction(Request $request) |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Displays a form to edit an existing Material entity. |
||
| 104 | * |
||
| 105 | * @Route("/admin/{slug}/edit", name="material_edit") |
||
| 106 | * @Method("GET") |
||
| 107 | * @Template() |
||
| 108 | */ |
||
| 109 | View Code Duplication | public function editAction(Material $material) |
|
| 117 | |||
| 118 | /** |
||
| 119 | * Edits an existing Material entity. |
||
| 120 | * |
||
| 121 | * @Route("/admin/{slug}/update", name="material_update") |
||
| 122 | * @Method("PUT") |
||
| 123 | * @Template("AppBundle:Settings\Diverse\Material:edit.html.twig") |
||
| 124 | */ |
||
| 125 | public function updateAction(Material $material, Request $request) |
||
| 131 | |||
| 132 | /** |
||
| 133 | * Save order. |
||
| 134 | * |
||
| 135 | * @Route("/order/{entity}/{field}/{type}", name="material_sort") |
||
| 136 | * |
||
| 137 | * @param string $entity Entity of the field to sort |
||
| 138 | * @param string $field Field to sort |
||
| 139 | * @param string $type type of sort |
||
| 140 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
| 141 | */ |
||
| 142 | public function sortAction($entity, $field, $type) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Deletes a Material entity. |
||
| 151 | * |
||
| 152 | * @Route("/{id}/delete", name="material_delete", requirements={"id"="\d+"}) |
||
| 153 | * @Method("DELETE") |
||
| 154 | */ |
||
| 155 | public function deleteAction(Material $material, Request $request) |
||
| 161 | } |
||
| 162 |