| Conditions | 13 |
| Paths | 1 |
| Total Lines | 81 |
| 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 |
||
| 23 | public function configureOptions(OptionsResolver $resolver) |
||
| 24 | { |
||
| 25 | $resolver |
||
| 26 | ->setDefaults([ |
||
| 27 | 'items' => [], |
||
| 28 | 'attr' => [], |
||
| 29 | 'position' => null, |
||
| 30 | 'css_class' => 'list-group nav flex-column navbar-nav menu-'.$this->menuName, |
||
| 31 | 'item_css_class' => '', |
||
| 32 | //list-group-item list-group-item-action', |
||
| 33 | 'link_css_class' => 'nav-link', |
||
| 34 | 'template' => '', |
||
| 35 | 'brand' => false, |
||
| 36 | ]) |
||
| 37 | ->setAllowedValues('position', [ |
||
| 38 | 'horizontal', |
||
| 39 | 'vertical', |
||
| 40 | null |
||
| 41 | ]) |
||
| 42 | ->setNormalizer('position', function (Options $options, $value) { |
||
| 43 | if ('top' === $this->menuName && null === $value) { |
||
| 44 | $value = 'horizontal'; |
||
| 45 | } |
||
| 46 | |||
| 47 | if ('left' === $this->menuName && null === $value) { |
||
| 48 | $value = 'vertical'; |
||
| 49 | } |
||
| 50 | |||
| 51 | return $value; |
||
| 52 | }) |
||
| 53 | ->setNormalizer('template', function (Options $options, $value) { |
||
| 54 | // Define bootstrap navbar component template |
||
| 55 | if ('horizontal' === $options->offsetGet('position')) { |
||
| 56 | $value = '@LAGAdmin/Menu/menu.horizontal.html.twig'; |
||
| 57 | |||
| 58 | } |
||
| 59 | |||
| 60 | // Define bootstrap nav component template |
||
| 61 | if ('vertical' === $options->offsetGet('position')) { |
||
| 62 | $value ='@LAGAdmin/Menu/menu.vertical.html.twig'; |
||
| 63 | } |
||
| 64 | |||
| 65 | return $value; |
||
| 66 | }) |
||
| 67 | ->setNormalizer('attr', function (Options $options, $value) { |
||
| 68 | $position = $options->offsetGet('position'); |
||
| 69 | |||
| 70 | if (!key_exists('class', $value)) { |
||
| 71 | $value['class'] = ''; |
||
| 72 | } |
||
| 73 | |||
| 74 | if ('horizontal' === $position) { |
||
| 75 | $value['class'] .= ' navbar navbar-expand-lg navbar-dark bg-dark fixed-top'; |
||
| 76 | } |
||
| 77 | |||
| 78 | if ('vertical' === $position) { |
||
| 79 | $value['class'] .= ' list-group'; |
||
| 80 | } |
||
| 81 | $value['class'] = trim($value['class']); |
||
| 82 | |||
| 83 | return $value; |
||
| 84 | }) |
||
| 85 | ->setNormalizer('item_css_class', function (Options $options, $value) { |
||
| 86 | $position = $options->offsetGet('position'); |
||
| 87 | |||
| 88 | if (!$value) { |
||
| 89 | $value = ''; |
||
| 90 | } |
||
| 91 | |||
| 92 | if ('horizontal' === $position) { |
||
| 93 | $value .= ' '; |
||
| 94 | } |
||
| 95 | |||
| 96 | if ('vertical' === $position) { |
||
| 97 | $value .= ' list-group-item list-group-item-action'; |
||
| 98 | } |
||
| 99 | |||
| 100 | return trim($value); |
||
| 101 | }) |
||
| 102 | ; |
||
| 103 | } |
||
| 104 | } |
||
| 105 |