| Conditions | 9 |
| Paths | 1 |
| Total Lines | 68 |
| Lines | 31 |
| Ratio | 45.59 % |
| 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 |
||
| 89 | protected function resolveActionConfiguration(ActionConfiguration $actionConfiguration, $value) |
||
| 90 | { |
||
| 91 | $resolver = new OptionsResolver(); |
||
| 92 | $resolver |
||
| 93 | ->setDefaults([ |
||
| 94 | 'title' => '', |
||
| 95 | 'icon' => '', |
||
| 96 | 'target' => '_self', |
||
| 97 | 'route' => '', |
||
| 98 | 'parameters' => [], |
||
| 99 | 'url' => '', |
||
| 100 | 'text' => '', |
||
| 101 | 'admin' => null, |
||
| 102 | 'action' => null, |
||
| 103 | 'class' => '', |
||
| 104 | ]) |
||
| 105 | ->setAllowedTypes('route', 'string') |
||
| 106 | ->setAllowedTypes('parameters', 'array') |
||
| 107 | ->setAllowedTypes('url', 'string') |
||
| 108 | ->setAllowedValues('target', [ |
||
| 109 | '_self', |
||
| 110 | '_blank', |
||
| 111 | ]) |
||
| 112 | View Code Duplication | ->setNormalizer('route', function (Options $options, $value) use ($actionConfiguration) { |
|
| 113 | // route or url should be defined |
||
| 114 | if (!$value && !$options->offsetGet('url') && !$options->offsetGet('admin')) { |
||
| 115 | throw new InvalidOptionsException( |
||
| 116 | 'You must set either an url or a route for the property' |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | |||
| 120 | if ($options->offsetGet('admin')) { |
||
| 121 | $value = RoutingLoader::generateRouteName( |
||
| 122 | $options->offsetGet('admin'), |
||
| 123 | $options->offsetGet('action'), |
||
| 124 | $actionConfiguration->getAdminConfiguration()->getParameter('routing_name_pattern') |
||
| 125 | ); |
||
| 126 | } |
||
| 127 | |||
| 128 | return $value; |
||
| 129 | }) |
||
| 130 | ->setNormalizer('admin', function (Options $options, $value) { |
||
| 131 | // if a Admin is defined, an Action should be defined too |
||
| 132 | if ($value && !$options->offsetGet('action')) { |
||
| 133 | throw new InvalidOptionsException( |
||
| 134 | 'An Action should be provided if an Admin is provided' |
||
| 135 | ); |
||
| 136 | } |
||
| 137 | |||
| 138 | return $value; |
||
| 139 | }) |
||
| 140 | View Code Duplication | ->setNormalizer('parameters', function (Options $options, $values) { |
|
| 141 | $cleanedValues = []; |
||
| 142 | |||
| 143 | foreach ($values as $name => $method) { |
||
| 144 | if (null === $method) { |
||
| 145 | $method = $name; |
||
| 146 | } |
||
| 147 | $cleanedValues[$name] = $method; |
||
| 148 | } |
||
| 149 | |||
| 150 | |||
| 151 | return $cleanedValues; |
||
| 152 | }) |
||
| 153 | ; |
||
| 154 | |||
| 155 | return $resolver->resolve($value); |
||
| 156 | } |
||
| 157 | } |
||
| 158 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.