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