| Conditions | 6 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 37 |
| 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 |
||
| 15 | public function configureOptions(OptionsResolver $resolver) |
||
| 16 | { |
||
| 17 | $resolver->setDefaults([ |
||
| 18 | 'length' => $this |
||
| 19 | ->applicationConfiguration |
||
| 20 | ->getParameter('string_length'), |
||
| 21 | 'replace' => $this |
||
| 22 | ->applicationConfiguration |
||
| 23 | ->getParameter('string_length_truncate'), |
||
| 24 | 'template' => $this |
||
| 25 | ->applicationConfiguration |
||
| 26 | ->getParameter('fields_template_mapping')[AbstractField::TYPE_LINK], |
||
| 27 | 'title' => '', |
||
| 28 | 'icon' => '', |
||
| 29 | 'target' => '_self', |
||
| 30 | 'route' => '', |
||
| 31 | 'parameters' => [], |
||
| 32 | 'url' => '', |
||
| 33 | 'text' => '', |
||
| 34 | 'admin' => null, |
||
| 35 | 'action' => null, |
||
| 36 | ]); |
||
| 37 | $resolver->setAllowedTypes('route', 'string'); |
||
| 38 | $resolver->setAllowedTypes('parameters', 'array'); |
||
| 39 | $resolver->setAllowedTypes('length', 'integer'); |
||
| 40 | $resolver->setAllowedTypes('url', 'string'); |
||
| 41 | $resolver->setAllowedValues('target', [ |
||
| 42 | '_self', |
||
| 43 | '_blank', |
||
| 44 | ]); |
||
| 45 | $resolver->setNormalizer('route', function(Options $options, $value) { |
||
| 46 | // route or url should be defined |
||
| 47 | if (!$value && !$options->offsetGet('url') && !$options->offsetGet('admin')) { |
||
| 48 | throw new InvalidOptionsException( |
||
| 49 | 'You must set either an url or a route for the property' |
||
| 50 | ); |
||
| 51 | } |
||
| 52 | |||
| 53 | return $value; |
||
| 54 | }); |
||
| 55 | $resolver->setNormalizer('admin', function(Options $options, $value) { |
||
| 56 | // if a Admin is defined, an Action should be defined too |
||
| 57 | if ($value && !$options->offsetGet('action')) { |
||
| 58 | throw new InvalidOptionsException( |
||
| 59 | 'An Action should be provided if an Admin is provided' |
||
| 60 | ); |
||
| 61 | } |
||
| 62 | |||
| 63 | return $value; |
||
| 64 | }); |
||
| 65 | } |
||
| 66 | } |
||
| 67 |