Conditions | 11 |
Paths | 1 |
Total Lines | 84 |
Code Lines | 55 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
31 | public function configureOptions(OptionsResolver $resolver, ActionConfiguration $actionConfiguration) |
||
32 | { |
||
33 | parent::configureOptions($resolver, $actionConfiguration); |
||
34 | |||
35 | $this->actionConfiguration = $actionConfiguration; |
||
36 | |||
37 | $resolver |
||
38 | ->setDefaults([ |
||
39 | 'template' => '@LAGAdmin/Field/link.html.twig', |
||
40 | 'title' => '', |
||
41 | 'icon' => '', |
||
42 | 'target' => '_self', |
||
43 | 'route' => '', |
||
44 | 'parameters' => [], |
||
45 | 'url' => '', |
||
46 | 'text' => '', |
||
47 | 'admin' => null, |
||
48 | 'action' => null, |
||
49 | 'class' => '', |
||
50 | ]) |
||
51 | ->setAllowedTypes('route', 'string') |
||
52 | ->setAllowedTypes('parameters', 'array') |
||
53 | ->setAllowedTypes('length', 'integer') |
||
54 | ->setAllowedTypes('url', 'string') |
||
55 | ->setAllowedValues('target', [ |
||
56 | '_self', |
||
57 | '_blank', |
||
58 | ]) |
||
59 | ->setNormalizer('route', function (Options $options, $value) use ($actionConfiguration) { |
||
60 | // route or url should be defined |
||
61 | if (!$value && !$options->offsetGet('url') && !$options->offsetGet('admin')) { |
||
62 | throw new InvalidOptionsException( |
||
63 | 'Either an url or a route should be defined' |
||
64 | ); |
||
65 | } |
||
66 | |||
67 | if ($options->offsetGet('admin')) { |
||
68 | $value = RoutingLoader::generateRouteName( |
||
69 | $options->offsetGet('admin'), |
||
70 | $options->offsetGet('action'), |
||
71 | $actionConfiguration->getAdminConfiguration()->getParameter('routing_name_pattern') |
||
72 | ); |
||
73 | } |
||
74 | |||
75 | return $value; |
||
76 | }) |
||
77 | ->setNormalizer('admin', function (Options $options, $value) { |
||
78 | // if a Admin is defined, an Action should be defined too |
||
79 | if ($value && !$options->offsetGet('action')) { |
||
80 | throw new InvalidOptionsException( |
||
81 | 'An Action should be provided if an Admin is provided' |
||
82 | ); |
||
83 | } |
||
84 | |||
85 | return $value; |
||
86 | }) |
||
87 | ->setNormalizer('parameters', function (Options $options, $values) { |
||
88 | $cleanedValues = []; |
||
89 | |||
90 | foreach ($values as $name => $method) { |
||
91 | if (null === $method) { |
||
92 | $method = $name; |
||
93 | } |
||
94 | $cleanedValues[$name] = $method; |
||
95 | } |
||
96 | |||
97 | return $cleanedValues; |
||
98 | }) |
||
99 | ->setNormalizer('text', function (Options $options, $value) use ($actionConfiguration) { |
||
100 | if ($value) { |
||
101 | return $value; |
||
102 | } |
||
103 | |||
104 | if ($options->offsetGet('action')) { |
||
105 | return $this |
||
106 | ->translator |
||
107 | ->trans(TranslationUtils::getActionTranslationKey( |
||
108 | $actionConfiguration->getAdminConfiguration()->get('translation_pattern'), |
||
109 | $actionConfiguration->getAdminName(), |
||
110 | $options->offsetGet('action') |
||
111 | )); |
||
112 | } |
||
113 | |||
114 | return $options->offsetGet('route'); |
||
115 | }) |
||
152 |