Conditions | 5 |
Paths | 6 |
Total Lines | 75 |
Code Lines | 33 |
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 namespace Anomaly\UsersModule\Role\Permission; |
||
26 | public function handle( |
||
27 | PermissionFormBuilder $builder, |
||
28 | AddonCollection $addons, |
||
29 | Translator $translator, |
||
30 | Repository $config |
||
31 | ) { |
||
32 | /* @var RoleInterface $role */ |
||
33 | $role = $builder->getEntry(); |
||
34 | |||
35 | $fields = []; |
||
36 | |||
37 | $namespaces = array_merge(['streams'], $addons->withConfig('permissions')->namespaces()); |
||
38 | |||
39 | /* |
||
40 | * gather all the addons with a |
||
41 | * permissions configuration file. |
||
42 | * |
||
43 | * @var Addon $addon |
||
44 | */ |
||
45 | foreach ($namespaces as $namespace) { |
||
46 | |||
47 | foreach ($config->get($namespace . '::permissions', []) as $group => $permissions) { |
||
48 | |||
49 | /* |
||
50 | * Determine the general |
||
51 | * form UI components. |
||
52 | */ |
||
53 | $label = $namespace . '::permission.' . $group . '.name'; |
||
54 | |||
55 | if (!$translator->has($warning = $namespace . '::permission.' . $group . '.warning')) { |
||
56 | $warning = null; |
||
57 | } |
||
58 | |||
59 | if (!$translator->has($instructions = $namespace . '::permission.' . $group . '.instructions')) { |
||
60 | $instructions = null; |
||
61 | } |
||
62 | |||
63 | /* |
||
64 | * Gather the available |
||
65 | * permissions for the group. |
||
66 | */ |
||
67 | $available = array_combine( |
||
68 | array_map( |
||
69 | function ($permission) use ($namespace, $group) { |
||
70 | return $namespace . '::' . $group . '.' . $permission; |
||
71 | }, |
||
72 | $permissions |
||
73 | ), |
||
74 | array_map( |
||
75 | function ($permission) use ($namespace, $group) { |
||
76 | return $namespace . '::permission.' . $group . '.option.' . $permission; |
||
77 | }, |
||
78 | $permissions |
||
79 | ) |
||
80 | ); |
||
81 | |||
82 | /* |
||
83 | * Build the checkboxes field |
||
84 | * type to handle the UI. |
||
85 | */ |
||
86 | $fields[str_replace('.', '_', $namespace . '::' . $group)] = [ |
||
87 | 'label' => $label, |
||
88 | 'warning' => $warning, |
||
89 | 'instructions' => $instructions, |
||
90 | 'type' => 'anomaly.field_type.checkboxes', |
||
91 | 'value' => $role->getPermissions(), |
||
92 | 'config' => [ |
||
93 | 'options' => $available, |
||
94 | ], |
||
95 | ]; |
||
96 | } |
||
97 | } |
||
98 | |||
99 | $builder->setFields($fields); |
||
100 | } |
||
101 | } |
||
102 |