Conditions | 7 |
Paths | 1 |
Total Lines | 100 |
Code Lines | 83 |
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 |
||
16 | public function getConfigTreeBuilder() |
||
17 | { |
||
18 | $treeBuilder = new TreeBuilder(); |
||
19 | $rootNode = $treeBuilder->root('norsys_logs'); |
||
20 | |||
21 | $rootNode |
||
22 | ->children() |
||
23 | ->arrayNode('security') |
||
24 | ->info('Optional security configuration') |
||
25 | ->addDefaultsIfNotSet() |
||
26 | ->children() |
||
27 | ->booleanNode('enabled') |
||
28 | ->info('Enable security to access logs') |
||
29 | ->defaultValue(true) |
||
30 | ->end() |
||
31 | ->arrayNode('allowed_ips') |
||
32 | ->prototype('scalar') |
||
33 | ->end() |
||
34 | ->defaultValue([]) |
||
35 | ->end() |
||
36 | ->end() |
||
37 | ->end() |
||
38 | ->scalarNode('base_layout') |
||
39 | ->cannotBeEmpty() |
||
40 | ->defaultValue('NorsysLogsBundle::layout.html.twig') |
||
41 | ->end() |
||
42 | ->scalarNode('logs_per_page') |
||
43 | ->cannotBeEmpty() |
||
44 | ->defaultValue(25) |
||
45 | ->beforeNormalization() |
||
46 | ->ifString() |
||
47 | ->then(function ($v) { |
||
48 | return (int) $v; |
||
49 | }) |
||
50 | ->end() |
||
51 | ->end() |
||
52 | ->arrayNode('doctrine') |
||
53 | ->children() |
||
54 | ->scalarNode('table_name')->defaultValue('monolog_entries')->end() |
||
55 | ->scalarNode('connection_name')->end() |
||
56 | ->arrayNode('connection') |
||
57 | ->cannotBeEmpty() |
||
58 | ->children() |
||
59 | ->scalarNode('driver')->end() |
||
60 | ->scalarNode('driverClass')->end() |
||
61 | ->scalarNode('pdo')->end() |
||
62 | ->scalarNode('dbname')->end() |
||
63 | ->scalarNode('host')->defaultValue('localhost')->end() |
||
64 | ->scalarNode('port')->defaultNull()->end() |
||
65 | ->scalarNode('user')->defaultValue('root')->end() |
||
66 | ->scalarNode('password')->defaultNull()->end() |
||
67 | ->scalarNode('charset')->defaultValue('UTF8')->end() |
||
68 | ->scalarNode('path') |
||
69 | ->info(' The filesystem path to the database file for SQLite') |
||
70 | ->end() |
||
71 | ->booleanNode('memory') |
||
72 | ->info('True if the SQLite database should be in-memory (non-persistent)') |
||
73 | ->end() |
||
74 | ->scalarNode('unix_socket') |
||
75 | ->info('The unix socket to use for MySQL') |
||
76 | ->end() |
||
77 | ->end() |
||
78 | ->end() |
||
79 | ->end() |
||
80 | ->end() |
||
81 | ->end() |
||
82 | ->validate() |
||
83 | ->ifTrue(function ($v) { |
||
84 | if (isset($v['doctrine']) === false) { |
||
85 | return true; |
||
86 | } |
||
87 | |||
88 | if (isset($v['doctrine']['connection_name']) === false |
||
89 | && isset($v['doctrine']['connection']) === false |
||
90 | ) { |
||
91 | return true; |
||
92 | } |
||
93 | |||
94 | return false; |
||
95 | }) |
||
96 | ->thenInvalid('You must provide a valid "connection_name" or "connection" definition.') |
||
97 | ->end() |
||
98 | ->validate() |
||
99 | ->ifTrue(function ($v) { |
||
100 | if (isset($v['doctrine']) === false) { |
||
101 | return true; |
||
102 | } |
||
103 | |||
104 | if (isset($v['doctrine']['connection_name']) === true |
||
105 | && isset($v['doctrine']['connection']) === true |
||
106 | ) { |
||
107 | return true; |
||
108 | } |
||
109 | |||
110 | return false; |
||
111 | }) |
||
112 | ->thenInvalid('You cannot specify both options "connection_name" and "connection".') |
||
113 | ->end(); |
||
114 | |||
115 | return $treeBuilder; |
||
116 | } |
||
118 |