Conditions | 11 |
Paths | 51 |
Total Lines | 47 |
Code Lines | 29 |
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 |
||
42 | public function configAction( |
||
43 | Request $request, |
||
44 | VariableApiInterface $variableApi, |
||
45 | PermissionRepositoryInterface $permissionRepository |
||
46 | ) { |
||
47 | $modVars = $variableApi->getAll('ZikulaPermissionsModule'); |
||
48 | $modVars['lockadmin'] = (bool)$modVars['lockadmin']; |
||
49 | $modVars['filter'] = (bool)$modVars['filter']; |
||
50 | |||
51 | $form = $this->createForm(ConfigType::class, $modVars); |
||
52 | $form->handleRequest($request); |
||
53 | if ($form->isSubmitted() && $form->isValid()) { |
||
54 | if ($form->get('save')->isClicked()) { |
||
|
|||
55 | $formData = $form->getData(); |
||
56 | |||
57 | $error = false; |
||
58 | |||
59 | $lockadmin = isset($formData['lockadmin']) ? (bool)$formData['lockadmin'] : false; |
||
60 | $variableApi->set('ZikulaPermissionsModule', 'lockadmin', $lockadmin); |
||
61 | |||
62 | $adminId = isset($formData['adminid']) ? (int)$formData['adminid'] : 1; |
||
63 | if (0 !== $adminId) { |
||
64 | $perm = $permissionRepository->find($adminId); |
||
65 | if (!$perm) { |
||
66 | $adminId = 0; |
||
67 | $error = true; |
||
68 | } |
||
69 | } |
||
70 | $variableApi->set('ZikulaPermissionsModule', 'adminid', $adminId); |
||
71 | |||
72 | $filter = isset($formData['filter']) ? (bool)$formData['filter'] : false; |
||
73 | $variableApi->set('ZikulaPermissionsModule', 'filter', $filter); |
||
74 | |||
75 | if (true === $error) { |
||
76 | $this->addFlash('error', 'Error! Could not save configuration: unknown permission rule ID.'); |
||
77 | } else { |
||
78 | $this->addFlash('status', 'Done! Configuration updated.'); |
||
79 | } |
||
80 | } elseif ($form->get('cancel')->isClicked()) { |
||
81 | $this->addFlash('status', 'Operation cancelled.'); |
||
82 | } |
||
83 | |||
84 | return $this->redirectToRoute('zikulapermissionsmodule_permission_list'); |
||
85 | } |
||
86 | |||
87 | return [ |
||
88 | 'form' => $form->createView() |
||
89 | ]; |
||
92 |