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 |
||
| 34 | class EntryController extends AbstractController |
||
|
|
|||
| 35 | { |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Index |
||
| 39 | * |
||
| 40 | * @param Application $app |
||
| 41 | * @param Request $request |
||
| 42 | * @return \Symfony\Component\HttpFoundation\Response |
||
| 43 | */ |
||
| 44 | 5 | public function index(Application $app, Request $request) |
|
| 45 | { |
||
| 46 | /** @var $Customer \Eccube\Entity\Customer */ |
||
| 47 | $Customer = $app['eccube.repository.customer']->newCustomer(); |
||
| 48 | |||
| 49 | /* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
||
| 50 | $builder = $app['form.factory']->createBuilder('entry', $Customer); |
||
| 51 | /* @var $form \Symfony\Component\Form\FormInterface */ |
||
| 52 | $form = $builder->getForm(); |
||
| 53 | $form->handleRequest($request); |
||
| 54 | |||
| 55 | if ($form->isSubmitted() && $form->isValid()) { |
||
| 56 | 2 | switch ($request->get('mode')) { |
|
| 57 | 2 | View Code Duplication | case 'confirm': |
| 58 | $builder->setAttribute('freeze', true); |
||
| 59 | $form = $builder->getForm(); |
||
| 60 | $form->handleRequest($request); |
||
| 61 | |||
| 62 | 1 | return $app['twig']->render('Entry/confirm.twig', array( |
|
| 63 | 1 | 'form' => $form->createView(), |
|
| 64 | )); |
||
| 65 | |||
| 66 | 1 | case 'complete': |
|
| 67 | $Customer |
||
| 68 | ->setSalt( |
||
| 69 | $app['eccube.repository.customer']->createSalt(5) |
||
| 70 | ) |
||
| 71 | ->setPassword( |
||
| 72 | $app['eccube.repository.customer']->encryptPassword($app, $Customer) |
||
| 73 | ) |
||
| 74 | ->setSecretKey( |
||
| 75 | $app['eccube.repository.customer']->getUniqueSecretKey($app) |
||
| 76 | ); |
||
| 77 | |||
| 78 | $CustomerAddress = new \Eccube\Entity\CustomerAddress(); |
||
| 79 | $CustomerAddress |
||
| 80 | ->setFromCustomer($Customer); |
||
| 81 | |||
| 82 | $app['orm.em']->persist($Customer); |
||
| 83 | $app['orm.em']->persist($CustomerAddress); |
||
| 84 | $app['orm.em']->flush(); |
||
| 85 | |||
| 86 | $activateUrl = $app->url('entry_activate', array('secret_key' => $Customer->getSecretKey())); |
||
| 87 | |||
| 88 | /** @var $BaseInfo \Eccube\Entity\BaseInfo */ |
||
| 89 | $BaseInfo = $app['eccube.repository.base_info']->get(); |
||
| 90 | $activateFlg = $BaseInfo->getOptionCustomerActivate(); |
||
| 91 | |||
| 92 | // 仮会員設定が有効な場合は、確認メールを送信し完了画面表示. |
||
| 93 | if ($activateFlg) { |
||
| 94 | // メール送信 |
||
| 95 | $app['eccube.service.mail']->sendCustomerConfirmMail($Customer, $activateUrl); |
||
| 96 | |||
| 97 | return $app->redirect($app->url('entry_complete')); |
||
| 98 | // 仮会員設定が無効な場合は認証URLへ遷移させ、会員登録を完了させる. |
||
| 99 | } else { |
||
| 100 | return $app->redirect($activateUrl); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | 4 | return $app['view']->render('Entry/index.twig', array( |
|
| 106 | 4 | 'form' => $form->createView(), |
|
| 107 | )); |
||
| 108 | 5 | } |
|
| 109 | |||
| 110 | /** |
||
| 111 | * Complete |
||
| 112 | * |
||
| 113 | * @param Application $app |
||
| 114 | * @return mixed |
||
| 115 | */ |
||
| 116 | 1 | public function complete(Application $app) |
|
| 120 | |||
| 121 | /** |
||
| 122 | * 会員のアクティベート(本会員化)を行う |
||
| 123 | * |
||
| 124 | * @param Application $app |
||
| 125 | * @param Request $request |
||
| 126 | * @param string $secret_key |
||
| 127 | * @return mixed |
||
| 128 | */ |
||
| 129 | 3 | public function activate(Application $app, Request $request, $secret_key) |
|
| 164 | } |
||
| 165 |