Conditions | 6 |
Paths | 10 |
Total Lines | 57 |
Code Lines | 35 |
Lines | 8 |
Ratio | 14.04 % |
Tests | 9 |
CRAP Score | 7.6394 |
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 |
||
33 | 5 | public function index(Application $app, Request $request) |
|
34 | { |
||
35 | |||
36 | /* @var $builder \Symfony\Component\Form\FormBuilderInterface */ |
||
37 | $builder = $app['form.factory']->createBuilder('contact'); |
||
38 | |||
39 | /* @var $form \Symfony\Component\Form\FormInterface */ |
||
40 | $form = $builder->getForm(); |
||
41 | |||
42 | if ($app['security']->isGranted('ROLE_USER')) { |
||
43 | /* @var $user \Eccube\Entity\Customer */ |
||
44 | $user = $app['user']; |
||
45 | $form->setData(array( |
||
46 | 'name01' => $user->getName01(), |
||
47 | 'name02' => $user->getName02(), |
||
48 | 'kana01' => $user->getKana01(), |
||
49 | 'kana02' => $user->getKana02(), |
||
50 | 'zip01' => $user->getZip01(), |
||
51 | 'zip02' => $user->getZip02(), |
||
52 | 'pref' => $user->getPref(), |
||
53 | 'addr01' => $user->getAddr01(), |
||
54 | 'addr02' => $user->getAddr02(), |
||
55 | 'tel01' => $user->getTel01(), |
||
56 | 'tel02' => $user->getTel02(), |
||
57 | 'tel03' => $user->getTel03(), |
||
58 | 'email' => $user->getEmail(), |
||
59 | )); |
||
60 | } |
||
61 | |||
62 | if ('POST' === $request->getMethod()) { |
||
63 | $form->handleRequest($request); |
||
64 | |||
65 | if ($form->isValid()) { |
||
66 | 4 | switch ($request->get('mode')) { |
|
67 | 4 | View Code Duplication | case 'confirm': |
68 | $builder->setAttribute('freeze', true); |
||
69 | $form = $builder->getForm(); |
||
70 | $form->handleRequest($request); |
||
71 | |||
72 | 1 | return $app->render('Contact/confirm.twig', array( |
|
73 | 1 | 'form' => $form->createView(), |
|
74 | )); |
||
75 | |||
76 | 3 | case 'complete': |
|
77 | // メール送信 |
||
78 | $app['eccube.service.mail']->sendrContactMail($form->getData()); |
||
79 | |||
80 | return $app->redirect($app->url('contact_complete')); |
||
81 | break; |
||
82 | } |
||
83 | } |
||
84 | } |
||
85 | |||
86 | 1 | return $app->render('Contact/index.twig', array( |
|
87 | 1 | 'form' => $form->createView(), |
|
88 | )); |
||
89 | 5 | } |
|
90 | |||
96 |