Conditions | 6 |
Paths | 6 |
Total Lines | 90 |
Code Lines | 56 |
Lines | 9 |
Ratio | 10 % |
Tests | 11 |
CRAP Score | 7.0986 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
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 | |||
52 | /* @var $form \Symfony\Component\Form\FormInterface */ |
||
53 | $form = $builder->getForm(); |
||
54 | if ('POST' === $request->getMethod()) { |
||
55 | $form->handleRequest($request); |
||
56 | |||
57 | if ($form->isValid()) { |
||
58 | 3 | switch ($request->get('mode')) { |
|
59 | 3 | View Code Duplication | case 'confirm': |
60 | $builder->setAttribute('freeze', true); |
||
61 | $form = $builder->getForm(); |
||
62 | $form->handleRequest($request); |
||
63 | |||
64 | 1 | return $app['twig']->render('Entry/confirm.twig', array( |
|
65 | 1 | 'form' => $form->createView(), |
|
66 | )); |
||
67 | break; |
||
68 | |||
69 | 2 | case 'complete': |
|
70 | $Customer->setSalt( |
||
71 | $app['eccube.repository.customer'] |
||
72 | ->createSalt(5) |
||
73 | ); |
||
74 | |||
75 | $Customer->setPassword( |
||
76 | $app['eccube.repository.customer']->encryptPassword($app, $Customer) |
||
77 | ); |
||
78 | |||
79 | $Customer->setSecretKey( |
||
80 | $app['eccube.repository.customer']->getUniqueSecretKey($app) |
||
81 | ); |
||
82 | |||
83 | $CustomerAddress = new \Eccube\Entity\CustomerAddress(); |
||
84 | $CustomerAddress->setName01($Customer->getName01()) |
||
85 | ->setName02($Customer->getName02()) |
||
86 | ->setKana01($Customer->getKana01()) |
||
87 | ->setKana02($Customer->getKana02()) |
||
88 | ->setCompanyName($Customer->getCompanyName()) |
||
89 | ->setZip01($Customer->getZip01()) |
||
90 | ->setZip02($Customer->getZip02()) |
||
91 | ->setZipcode($Customer->getZip01() . $Customer->getZip02()) |
||
92 | ->setPref($Customer->getPref()) |
||
93 | ->setAddr01($Customer->getAddr01()) |
||
94 | ->setAddr02($Customer->getAddr02()) |
||
95 | ->setTel01($Customer->getTel01()) |
||
96 | ->setTel02($Customer->getTel02()) |
||
97 | ->setTel03($Customer->getTel03()) |
||
98 | ->setFax01($Customer->getFax01()) |
||
99 | ->setFax02($Customer->getFax02()) |
||
100 | ->setFax03($Customer->getFax03()) |
||
101 | 1 | ->setDelFlg(Constant::DISABLED) |
|
102 | ->setCustomer($Customer); |
||
103 | |||
104 | $app['orm.em']->persist($Customer); |
||
105 | $app['orm.em']->persist($CustomerAddress); |
||
106 | $app['orm.em']->flush(); |
||
107 | |||
108 | $activateUrl = $app->url('entry_activate', array('secret_key' => $Customer->getSecretKey())); |
||
109 | |||
110 | /** @var $BaseInfo \Eccube\Entity\BaseInfo */ |
||
111 | $BaseInfo = $app['eccube.repository.base_info']->get(); |
||
112 | $activateFlg = $BaseInfo->getOptionCustomerActivate(); |
||
113 | |||
114 | // 仮会員設定が有効な場合は、確認メールを送信し完了画面表示. |
||
115 | 1 | if ($activateFlg) { |
|
116 | |||
117 | // メール送信 |
||
118 | $app['eccube.service.mail']->sendCustomerConfirmMail($Customer, $activateUrl); |
||
119 | |||
120 | return $app->redirect($app->url('entry_complete')); |
||
121 | |||
122 | // 仮会員設定が無効な場合は認証URLへ遷移させ、会員登録を完了させる. |
||
123 | } else { |
||
124 | return $app->redirect($activateUrl); |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | |||
130 | 3 | return $app['view']->render('Entry/index.twig', array( |
|
131 | 3 | 'form' => $form->createView(), |
|
132 | )); |
||
133 | 5 | } |
|
134 | |||
192 |