Conditions | 1 |
Paths | 1 |
Total Lines | 55 |
Code Lines | 48 |
Lines | 0 |
Ratio | 0 % |
Tests | 47 |
CRAP Score | 1 |
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 |
||
36 | 21 | protected function addGetMethodOverride(ArrayNodeDefinition $rootNode): void |
|
37 | { |
||
38 | 21 | $overridableHttpMethods = $this->getOverridableHttpMethods(); |
|
39 | $defaultOverridedHttpMethods = [ |
||
40 | 21 | Request::METHOD_DELETE, |
|
41 | 21 | Request::METHOD_POST, |
|
42 | 21 | Request::METHOD_PUT, |
|
43 | ]; |
||
44 | |||
45 | $rootNode |
||
46 | 21 | ->children() |
|
47 | 21 | ->arrayNode('get_method_override') |
|
48 | 21 | ->info('Default options for GET method override feature') |
|
49 | 21 | ->addDefaultsIfNotSet() |
|
50 | 21 | ->canBeEnabled() |
|
51 | 21 | ->children() |
|
52 | 21 | ->scalarNode('listener_service_id') |
|
53 | 21 | ->cannotBeEmpty() |
|
54 | 21 | ->defaultValue('spiechu_symfony_commons.event_listener.get_method_override_listener') |
|
55 | 21 | ->end() |
|
56 | 21 | ->scalarNode('query_param_name') |
|
1 ignored issue
–
show
|
|||
57 | 21 | ->cannotBeEmpty() |
|
58 | 21 | ->defaultValue('_method') |
|
59 | 21 | ->validate() |
|
60 | ->ifTrue(function ($methodName): bool { |
||
61 | 1 | return !\is_string($methodName); |
|
62 | 21 | }) |
|
63 | 21 | ->thenInvalid('Not a string provided') |
|
64 | 21 | ->end() |
|
65 | 21 | ->end() |
|
66 | 21 | ->arrayNode('allow_methods_override') |
|
67 | 21 | ->beforeNormalization() |
|
68 | 21 | ->ifString()->castToArray() |
|
69 | 21 | ->end() |
|
70 | 21 | ->defaultValue($defaultOverridedHttpMethods) |
|
71 | 21 | ->prototype('scalar') |
|
72 | 21 | ->validate() |
|
73 | 21 | ->ifNotInArray($overridableHttpMethods) |
|
74 | 21 | ->thenInvalid(sprintf( |
|
75 | 21 | 'Invalid methods to override provided, known are: "%s"', |
|
76 | 21 | implode(', ', $overridableHttpMethods) |
|
77 | )) |
||
78 | 21 | ->end() |
|
79 | 21 | ->end() |
|
80 | 21 | ->beforeNormalization() |
|
81 | 21 | ->ifArray() |
|
82 | ->then(function (array $methods): array { |
||
83 | 4 | return array_unique(array_map('strtoupper', $methods)); |
|
84 | 21 | }) |
|
85 | 21 | ->end() |
|
86 | 21 | ->end() |
|
87 | 21 | ->end() |
|
88 | 21 | ->end() |
|
89 | 21 | ->end() |
|
90 | 21 | ->end(); |
|
91 | 21 | } |
|
197 |