| Conditions | 13 |
| Paths | 4 |
| Total Lines | 97 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 12 | ||
| Bugs | 2 | Features | 1 |
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 |
||
| 112 | protected function configureOptionsResolver(OptionsResolver $resolver, $actionName, AdminInterface $admin = null) |
||
| 113 | { |
||
| 114 | $defaultCriteria = []; |
||
| 115 | $defaultLoadStrategy = Admin::LOAD_STRATEGY_UNIQUE; |
||
| 116 | |||
| 117 | if ($actionName == 'edit') { |
||
| 118 | $defaultCriteria = [ |
||
| 119 | 'id' |
||
| 120 | ]; |
||
| 121 | } else if ($actionName == 'delete') { |
||
| 122 | $defaultCriteria = [ |
||
| 123 | 'id' |
||
| 124 | ]; |
||
| 125 | } else if ($actionName == 'create') { |
||
| 126 | $defaultLoadStrategy = Admin::LOAD_STRATEGY_NONE; |
||
| 127 | } |
||
| 128 | |||
| 129 | $resolver |
||
| 130 | ->setDefaults([ |
||
| 131 | 'title' => null, |
||
| 132 | 'fields' => [ |
||
| 133 | 'id' => [], |
||
| 134 | ], |
||
| 135 | 'permissions' => [ |
||
| 136 | 'ROLE_ADMIN' |
||
| 137 | ], |
||
| 138 | 'export' => [ |
||
| 139 | 'json', |
||
| 140 | 'html', |
||
| 141 | 'csv', |
||
| 142 | 'xls' |
||
| 143 | ], |
||
| 144 | 'order' => [], |
||
| 145 | 'actions' => [], |
||
| 146 | 'submit_actions' => [], |
||
| 147 | 'target' => '_self', |
||
| 148 | 'route' => '', |
||
| 149 | 'parameters' => [], |
||
| 150 | 'icon' => null, |
||
| 151 | 'filters' => [], |
||
| 152 | 'batch' => [], |
||
| 153 | 'load_strategy' => $defaultLoadStrategy, |
||
| 154 | 'pager' => 'pagerfanta', |
||
| 155 | 'criteria' => $defaultCriteria |
||
| 156 | ]) |
||
| 157 | ->setAllowedValues('pager', [ |
||
| 158 | null, |
||
| 159 | 'pagerfanta', |
||
| 160 | ]) |
||
| 161 | ->setAllowedValues('load_strategy', [ |
||
| 162 | Admin::LOAD_STRATEGY_NONE, |
||
| 163 | Admin::LOAD_STRATEGY_UNIQUE, |
||
| 164 | Admin::LOAD_STRATEGY_MULTIPLE, |
||
| 165 | ]) |
||
| 166 | ->setAllowedTypes('actions', 'array') |
||
| 167 | ->setNormalizer('route', function (Options $options, $value) use ($admin, $actionName) { |
||
| 168 | if (!$value) { |
||
| 169 | // if no route was provided, it should be linked to an Admin |
||
| 170 | if (!$admin) { |
||
| 171 | throw new Exception('No route was provided for action : ' . $actionName); |
||
| 172 | } |
||
| 173 | return $admin |
||
| 174 | ->generateRouteName($actionName); |
||
| 175 | } |
||
| 176 | return $value; |
||
| 177 | }) |
||
| 178 | ->setNormalizer('title', function (Options $options, $value) use ($admin, $actionName) { |
||
| 179 | if (!$value) { |
||
| 180 | $adminKey = ''; |
||
| 181 | // if an Admin is linked to this action, we use its name in translation key |
||
| 182 | if ($admin) { |
||
| 183 | $adminKey = $admin->getName(); |
||
| 184 | } |
||
| 185 | return $this->configuration->getTranslationKey($actionName, $adminKey); |
||
| 186 | } |
||
| 187 | return $value; |
||
| 188 | }) |
||
| 189 | ->setNormalizer('batch', function (Options $options, $value) use ($admin, $actionName) { |
||
| 190 | if ($value) { |
||
| 191 | if (!is_array($value)) { |
||
| 192 | $value = [$value]; |
||
| 193 | } |
||
| 194 | foreach ($value as $key => $title) { |
||
| 195 | if (!$title) { |
||
| 196 | $adminKey = ''; |
||
| 197 | // if an Admin is linked to this action, we use its name in translation key |
||
| 198 | if ($admin) { |
||
| 199 | $adminKey = $admin->getName(); |
||
| 200 | } |
||
| 201 | $value[$key] = $this->configuration->getTranslationKey('batch.' . $key, $adminKey); |
||
| 202 | } |
||
| 203 | } |
||
| 204 | } |
||
| 205 | return $value; |
||
| 206 | }) |
||
| 207 | ; |
||
| 208 | } |
||
| 209 | } |
||
| 210 |