Conditions | 3 |
Paths | 1 |
Total Lines | 79 |
Code Lines | 70 |
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 |
||
20 | public function getConfigTreeBuilder() |
||
21 | { |
||
22 | $treeBuilder = new TreeBuilder(); |
||
23 | $rootNode = $treeBuilder->root('norsys_security'); |
||
24 | |||
25 | $rootNode |
||
26 | ->children() |
||
27 | ->arrayNode('https_redirect') |
||
28 | ->info('Optional https redirect configuration') |
||
29 | ->addDefaultsIfNotSet() |
||
30 | ->children() |
||
31 | ->booleanNode('enabled') |
||
32 | ->info('Enable force redirect to https') |
||
33 | ->defaultValue(false) |
||
34 | ->end() |
||
35 | ->end() |
||
36 | ->end() |
||
37 | ->arrayNode('proxy') |
||
38 | ->info('Optional proxy configuration') |
||
39 | ->addDefaultsIfNotSet() |
||
40 | ->children() |
||
41 | ->booleanNode('enabled') |
||
42 | ->info('Enable proxy') |
||
43 | ->defaultValue(false) |
||
44 | ->end() |
||
45 | ->scalarNode('env_variable_name') |
||
46 | ->info('Configure name to environment variable list trusted proxies') |
||
47 | ->defaultValue('TRUSTED_PROXIES') |
||
48 | ->end() |
||
49 | ->scalarNode('env_variable_separator') |
||
50 | ->info('Configure proxy separator in environment variable listed trusted proxies') |
||
51 | ->defaultValue(',') |
||
52 | ->end() |
||
53 | ->scalarNode('trusted_header_set') |
||
54 | ->info('A bit field of Request::HEADER_*, to set which headers to trust from your proxies') |
||
55 | ->defaultValue(Request::HEADER_X_FORWARDED_ALL) |
||
56 | ->validate() |
||
57 | ->ifEmpty() |
||
58 | ->then(function () { |
||
59 | return Request::HEADER_X_FORWARDED_ALL; |
||
60 | }) |
||
61 | ->end() |
||
62 | ->validate() |
||
63 | ->ifTrue( |
||
64 | function (string $header) { |
||
65 | if (preg_match('/^HEADER_FORWARDED$|^HEADER_X_[\w]+$/', $header) === 0 |
||
66 | || defined(Request::class . '::' . $header) === false |
||
67 | ) { |
||
68 | return true; |
||
69 | } |
||
70 | } |
||
71 | ) |
||
72 | ->thenInvalid('Invalid header to trust from your proxies %s') |
||
73 | ->end() |
||
74 | ->end() |
||
75 | ->end() |
||
76 | ->end() |
||
77 | ->arrayNode('coming_soon') |
||
78 | ->info('Optional coming soon configuration') |
||
79 | ->addDefaultsIfNotSet() |
||
80 | ->children() |
||
81 | ->booleanNode('enabled') |
||
82 | ->info('Redirect all requests to coming soon page') |
||
83 | ->defaultValue(false) |
||
84 | ->end() |
||
85 | ->scalarNode('template') |
||
86 | ->info('Template to display coming soon page') |
||
87 | ->defaultValue('NorsysSecurityBundle::coming_soon.html.twig') |
||
88 | ->end() |
||
89 | ->arrayNode('allowed_ips') |
||
90 | ->prototype('scalar') |
||
91 | ->end() |
||
92 | ->defaultValue([]) |
||
93 | ->end() |
||
94 | ->end() |
||
95 | ->end() |
||
96 | ->end(); |
||
97 | |||
98 | return $treeBuilder; |
||
99 | } |
||
101 |