| Conditions | 16 |
| Paths | 1 |
| Total Lines | 88 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 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 |
||
| 32 | public function configureOptions(OptionsResolver $resolver) |
||
| 33 | { |
||
| 34 | $resolver |
||
| 35 | ->setDefaults([ |
||
| 36 | 'items' => [], |
||
| 37 | 'attr' => [], |
||
| 38 | 'position' => null, |
||
| 39 | 'css_class' => 'list-group nav flex-column navbar-nav menu-'.$this->menuName, |
||
| 40 | 'item_css_class' => '', |
||
| 41 | 'link_css_class' => 'nav-link', |
||
| 42 | 'template' => '', |
||
| 43 | 'brand' => null, |
||
| 44 | ]) |
||
| 45 | ->setAllowedValues('position', [ |
||
| 46 | 'horizontal', |
||
| 47 | 'vertical', |
||
| 48 | null, |
||
| 49 | ]) |
||
| 50 | ->setNormalizer('position', function (Options $options, $value) { |
||
| 51 | if ('top' === $this->menuName && null === $value) { |
||
| 52 | $value = 'horizontal'; |
||
| 53 | } |
||
| 54 | |||
| 55 | if ('left' === $this->menuName && null === $value) { |
||
| 56 | $value = 'vertical'; |
||
| 57 | } |
||
| 58 | |||
| 59 | return $value; |
||
| 60 | }) |
||
| 61 | ->setNormalizer('template', function (Options $options, $value) { |
||
| 62 | // Define bootstrap navbar component template |
||
| 63 | if ('horizontal' === $options->offsetGet('position')) { |
||
| 64 | $value = '@LAGAdmin/Menu/menu.horizontal.html.twig'; |
||
| 65 | } |
||
| 66 | |||
| 67 | // Define bootstrap nav component template |
||
| 68 | if ('vertical' === $options->offsetGet('position')) { |
||
| 69 | $value = '@LAGAdmin/Menu/menu.vertical.html.twig'; |
||
| 70 | } |
||
| 71 | |||
| 72 | return $value; |
||
| 73 | }) |
||
| 74 | ->setNormalizer('attr', function (Options $options, $value) { |
||
| 75 | $position = $options->offsetGet('position'); |
||
| 76 | |||
| 77 | if (!key_exists('class', $value)) { |
||
| 78 | $value['class'] = ''; |
||
| 79 | } |
||
| 80 | |||
| 81 | if ('horizontal' === $position) { |
||
| 82 | $value['class'] .= ' navbar navbar-expand-lg navbar-dark bg-dark fixed-top'; |
||
| 83 | } |
||
| 84 | |||
| 85 | if ('vertical' === $position) { |
||
| 86 | $value['class'] .= ' list-group'; |
||
| 87 | } |
||
| 88 | $value['class'] = trim($value['class']); |
||
| 89 | |||
| 90 | // Do not return an array with an empty string as css class |
||
| 91 | if ('' === $value['class']) { |
||
| 92 | unset($value['class']); |
||
| 93 | } |
||
| 94 | |||
| 95 | return $value; |
||
| 96 | }) |
||
| 97 | ->setNormalizer('item_css_class', function (Options $options, $value) { |
||
| 98 | $position = $options->offsetGet('position'); |
||
| 99 | |||
| 100 | if (!$value) { |
||
| 101 | $value = ''; |
||
| 102 | } |
||
| 103 | |||
| 104 | if ('horizontal' === $position) { |
||
| 105 | $value .= ' navbar-nav mr-auto'; |
||
| 106 | } |
||
| 107 | |||
| 108 | if ('vertical' === $position) { |
||
| 109 | $value .= ' list-group-item list-group-item-action'; |
||
| 110 | } |
||
| 111 | |||
| 112 | return trim($value); |
||
| 113 | }) |
||
| 114 | ->setNormalizer('brand', function (Options $options, $value) { |
||
| 115 | if (null === $value && 'horizontal' === $options->offsetGet('position')) { |
||
| 116 | $value = $this->applicationName; |
||
| 117 | } |
||
| 118 | |||
| 119 | return $value; |
||
| 120 | }) |
||
| 134 |