Conditions | 4 |
Paths | 1 |
Total Lines | 100 |
Code Lines | 72 |
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 |
||
24 | protected function configureOptions(OptionsResolver $resolver): void |
||
25 | { |
||
26 | $resolver |
||
27 | ->setRequired('entity') |
||
28 | ->setAllowedTypes('entity', 'string') |
||
29 | ->setRequired('name') |
||
30 | ->setAllowedTypes('name', 'string') |
||
31 | ->setDefault('title', null) |
||
32 | ->setAllowedTypes('title', ['string', 'null']) |
||
33 | ->addNormalizer('title', function (Options $options, $value) { |
||
34 | if ($value === null) { |
||
35 | $value = u($options->offsetGet('name'))->title()->toString(); |
||
36 | } |
||
37 | |||
38 | return $value; |
||
39 | }) |
||
40 | |||
41 | ->setDefault('actions', [ |
||
42 | 'list' => [], |
||
43 | 'create' => [], |
||
44 | 'edit' => [], |
||
45 | 'delete' => [], |
||
46 | ]) |
||
47 | ->setAllowedTypes('actions', 'array') |
||
48 | ->setNormalizer('actions', $this->getActionNormalizer()) |
||
49 | |||
50 | ->setDefault('list_actions', [ |
||
51 | 'edit' => [], |
||
52 | 'delete' => [], |
||
53 | ]) |
||
54 | ->setAllowedTypes('list_actions', 'array') |
||
55 | ->setNormalizer('list_actions', function (Options $options, $value) { |
||
56 | foreach ($value as $actionName => $actionConfiguration) { |
||
57 | $value[$actionName] = LinkNormalizer::normalize( |
||
58 | $actionConfiguration, |
||
59 | $options->offsetGet('name'), |
||
60 | $actionName |
||
61 | ); |
||
62 | } |
||
63 | |||
64 | return $value; |
||
65 | }) |
||
66 | |||
67 | ->setDefault('item_actions', [ |
||
68 | 'create' => [], |
||
69 | ]) |
||
70 | ->setAllowedTypes('item_actions', 'array') |
||
71 | ->setNormalizer('item_actions', function (Options $options, $value) { |
||
72 | foreach ($value as $actionName => $actionConfiguration) { |
||
73 | $value[$actionName] = LinkNormalizer::normalize( |
||
74 | $actionConfiguration, |
||
75 | $options->offsetGet('name'), |
||
76 | $actionName |
||
77 | ); |
||
78 | } |
||
79 | |||
80 | return $value; |
||
81 | }) |
||
82 | |||
83 | ->setDefault('controller', AdminAction::class) |
||
84 | ->setAllowedTypes('controller', 'string') |
||
85 | |||
86 | ->setDefault('batch', []) |
||
87 | ->setAllowedTypes('batch', 'array') |
||
88 | |||
89 | ->setDefault('admin_class', Admin::class) |
||
90 | ->setAllowedTypes('admin_class', 'string') |
||
91 | ->setDefault('action_class', Action::class) |
||
92 | ->setAllowedTypes('action_class', 'string') |
||
93 | |||
94 | ->setDefault('routes_pattern', 'lag_admin.{admin}.{action}') |
||
95 | ->setAllowedTypes('routes_pattern', 'string') |
||
96 | ->setNormalizer('routes_pattern', $this->getRoutesPatternNormalizer()) |
||
97 | |||
98 | ->setDefault('pager', 'pagerfanta') |
||
99 | ->setAllowedValues('pager', ['pagerfanta', false]) |
||
100 | ->setDefault('max_per_page', 25) |
||
101 | ->setAllowedTypes('max_per_page', 'integer') |
||
102 | ->setDefault('page_parameter', 'page') |
||
103 | ->setAllowedTypes('page_parameter', 'string') |
||
104 | |||
105 | ->setDefault('permissions', 'ROLE_ADMIN') |
||
106 | ->setAllowedTypes('permissions', 'string') |
||
107 | |||
108 | ->setDefault('date_format', 'Y-m-d') |
||
109 | ->setAllowedTypes('date_format', 'string') |
||
110 | |||
111 | ->setDefault('data_provider', 'doctrine') |
||
112 | ->setAllowedTypes('data_provider', 'string') |
||
113 | ->setDefault('data_persister', 'doctrine') |
||
114 | ->setAllowedTypes('data_persister', 'string') |
||
115 | |||
116 | ->setDefault('create_template', '@LAGAdmin/crud/create.html.twig') |
||
117 | ->setAllowedTypes('create_template', 'string') |
||
118 | ->setDefault('edit_template', '@LAGAdmin/crud/edit.html.twig') |
||
119 | ->setAllowedTypes('edit_template', 'string') |
||
120 | ->setDefault('list_template', '@LAGAdmin/crud/list.html.twig') |
||
121 | ->setAllowedTypes('list_template', 'string') |
||
122 | ->setDefault('delete_template', '@LAGAdmin/crud/delete.html.twig') |
||
123 | ->setAllowedTypes('delete_template', 'string') |
||
124 | ; |
||
326 |