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 |
||
| 37 | class NewsController extends AbstractController |
||
| 38 | { |
||
| 39 | /** |
||
|
|
|||
| 40 | * 新着情報一覧を表示する。 |
||
| 41 | * |
||
| 42 | * @param Application $app |
||
| 43 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 44 | */ |
||
| 45 | 2 | public function index(Application $app, Request $request) |
|
| 46 | { |
||
| 47 | 2 | $NewsList = $app['eccube.repository.news']->findBy(array(), array('rank' => 'DESC')); |
|
| 48 | |||
| 49 | 2 | $builder = $app->form(); |
|
| 50 | |||
| 51 | 2 | $event = new EventArgs( |
|
| 52 | array( |
||
| 53 | 2 | 'builder' => $builder, |
|
| 54 | 2 | 'NewsList' => $NewsList, |
|
| 55 | ), |
||
| 56 | $request |
||
| 57 | ); |
||
| 58 | 2 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_CONTENT_NEWS_INDEX_INITIALIZE, $event); |
|
| 59 | |||
| 60 | 2 | $form = $builder->getForm(); |
|
| 61 | |||
| 62 | 2 | return $app->render('Content/news.twig', array( |
|
| 63 | 2 | 'form' => $form->createView(), |
|
| 64 | 2 | 'NewsList' => $NewsList, |
|
| 65 | )); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * 新着情報を登録・編集する。 |
||
| 70 | * |
||
| 71 | * @param Application $app |
||
| 72 | * @param Request $request |
||
| 73 | * @param integer $id |
||
| 74 | * @throws NotFoundHttpException |
||
| 75 | * @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response |
||
| 76 | */ |
||
| 77 | 5 | public function edit(Application $app, Request $request, $id = null) |
|
| 137 | |||
| 138 | /** |
||
| 139 | * 指定した新着情報の表示順を1つ上げる。 |
||
| 140 | * |
||
| 141 | * @param Application $app |
||
| 142 | * @param Request $request |
||
| 143 | * @param integer $id |
||
| 144 | * @throws NotFoundHttpException |
||
| 145 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
| 146 | */ |
||
| 147 | 2 | View Code Duplication | public function up(Application $app, Request $request, $id) |
| 166 | |||
| 167 | /** |
||
| 168 | * 指定した新着情報の表示順を1つ下げる。 |
||
| 169 | * |
||
| 170 | * @param Application $app |
||
| 171 | * @param Request $request |
||
| 172 | * @param integer $id |
||
| 173 | * @throws NotFoundHttpException |
||
| 174 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
| 175 | */ |
||
| 176 | 2 | View Code Duplication | public function down(Application $app, Request $request, $id) |
| 195 | |||
| 196 | /** |
||
| 197 | * 指定した新着情報を削除する。 |
||
| 198 | * |
||
| 199 | * @param Application $app |
||
| 200 | * @param Request $request |
||
| 201 | * @param integer $id |
||
| 202 | * @throws NotFoundHttpException |
||
| 203 | * @return \Symfony\Component\HttpFoundation\RedirectResponse |
||
| 204 | */ |
||
| 205 | 2 | public function delete(Application $app, Request $request, $id) |
|
| 234 | } |