| Conditions | 8 |
| Paths | 12 |
| Total Lines | 71 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 36 | public function index(Application $app, Request $request, $entity = null) |
||
| 37 | { |
||
| 38 | $data = array(); |
||
| 39 | |||
| 40 | $builder = $app['form.factory']->createBuilder('admin_system_masterdata'); |
||
| 41 | |||
| 42 | $event = new EventArgs( |
||
| 43 | array( |
||
| 44 | 'builder' => $builder, |
||
| 45 | ), |
||
| 46 | $request |
||
| 47 | ); |
||
| 48 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_INITIALIZE, $event); |
||
| 49 | |||
| 50 | $form = $builder->getForm(); |
||
| 51 | |||
| 52 | if ('POST' === $request->getMethod()) { |
||
| 53 | $form->handleRequest($request); |
||
| 54 | if ($form->isValid()) { |
||
| 55 | $event = new EventArgs( |
||
| 56 | array( |
||
| 57 | 'form' => $form, |
||
| 58 | ), |
||
| 59 | $request |
||
| 60 | ); |
||
| 61 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_COMPLETE, $event); |
||
| 62 | |||
| 63 | if ($event->hasResponse()) { |
||
| 64 | return $event->getResponse(); |
||
| 65 | } |
||
| 66 | |||
| 67 | return $app->redirect($app->url('admin_setting_system_masterdata_view', array('entity' => $form['masterdata']->getData()))); |
||
| 68 | } |
||
| 69 | } elseif (!is_null($entity)) { |
||
| 70 | $form->submit(array('masterdata' => $entity)); |
||
| 71 | if ($form['masterdata']->isValid()) { |
||
| 72 | $entityName = str_replace('-', '\\', $entity); |
||
| 73 | try { |
||
| 74 | $masterdata = $app['orm.em']->getRepository($entityName)->findBy(array(), array('rank' => 'ASC')); |
||
| 75 | $data['data'] = array(); |
||
| 76 | $data['masterdata_name'] = $entity; |
||
| 77 | foreach ($masterdata as $value) { |
||
| 78 | $data['data'][$value['id']]['id'] = $value['id']; |
||
| 79 | $data['data'][$value['id']]['name'] = $value['name']; |
||
| 80 | } |
||
| 81 | $data['data'][] = array( |
||
| 82 | 'id' => '', |
||
| 83 | 'name' => '', |
||
| 84 | ); |
||
| 85 | } catch (MappingException $e) { |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | $builder2 = $app['form.factory']->createBuilder('admin_system_masterdata_edit', $data); |
||
| 91 | |||
| 92 | $event = new EventArgs( |
||
| 93 | array( |
||
| 94 | 'builder' => $builder2, |
||
| 95 | ), |
||
| 96 | $request |
||
| 97 | ); |
||
| 98 | $app['eccube.event.dispatcher']->dispatch(EccubeEvents::ADMIN_SETTING_SYSTEM_MASTERDATA_INDEX_FORM2_INITIALIZE, $event); |
||
| 99 | |||
| 100 | $form2 = $builder2->getForm(); |
||
| 101 | |||
| 102 | return $app->render('Setting/System/masterdata.twig', array( |
||
| 103 | 'form' => $form->createView(), |
||
| 104 | 'form2' => $form2->createView(), |
||
| 105 | )); |
||
| 106 | } |
||
| 107 | |||
| 188 |