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