Conditions | 23 |
Paths | 1 |
Total Lines | 67 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
54 | private function getProvidersNode(): ArrayNodeDefinition |
||
55 | { |
||
56 | $treeBuilder = new TreeBuilder('providers'); |
||
57 | |||
58 | return $this->getRootNode($treeBuilder, 'providers') |
||
59 | ->requiresAtLeastOneElement() |
||
60 | ->useAttributeAsKey('name') |
||
61 | ->variablePrototype() |
||
62 | ->validate() |
||
63 | ->ifEmpty() |
||
64 | ->thenInvalid('Invalid provider configuration %s') |
||
65 | ->end() |
||
66 | ->end() |
||
67 | |||
68 | ->validate() |
||
69 | ->always() |
||
70 | ->then(static function ($v) { |
||
71 | if (!\array_key_exists('doctrine', $v)) { |
||
72 | $v['doctrine'] = []; |
||
73 | } |
||
74 | |||
75 | // "table_prefix" is empty by default. |
||
76 | if (!\array_key_exists('table_prefix', $v['doctrine']) || !\is_string($v['doctrine']['table_prefix'])) { |
||
77 | $v['doctrine']['table_prefix'] = ''; |
||
78 | } |
||
79 | |||
80 | // "table_suffix" is "_audit" by default. |
||
81 | if (!\array_key_exists('table_suffix', $v['doctrine']) || !\is_string($v['doctrine']['table_suffix'])) { |
||
82 | $v['doctrine']['table_suffix'] = '_audit'; |
||
83 | } |
||
84 | |||
85 | // "entities" are "enabled" by default. |
||
86 | if (\array_key_exists('entities', $v['doctrine']) && \is_array($v['doctrine']['entities'])) { |
||
87 | foreach ($v['doctrine']['entities'] as $entity => $options) { |
||
88 | if (null === $options || !\array_key_exists('enabled', $options)) { |
||
89 | $v['doctrine']['entities'][$entity]['enabled'] = true; |
||
90 | } |
||
91 | } |
||
92 | } |
||
93 | |||
94 | // "doctrine.orm.default_entity_manager" is the default "storage_services" |
||
95 | if (\array_key_exists('storage_services', $v['doctrine']) && \is_string($v['doctrine']['storage_services'])) { |
||
96 | $v['doctrine']['storage_services'] = [$v['doctrine']['storage_services']]; |
||
97 | } elseif (!\array_key_exists('storage_services', $v['doctrine']) || !\is_array($v['doctrine']['storage_services'])) { |
||
98 | $v['doctrine']['storage_services'] = ['doctrine.orm.default_entity_manager']; |
||
99 | } |
||
100 | |||
101 | // "doctrine.orm.default_entity_manager" is the default "auditing_services" |
||
102 | if (\array_key_exists('auditing_services', $v['doctrine']) && \is_string($v['doctrine']['auditing_services'])) { |
||
103 | $v['doctrine']['auditing_services'] = [$v['doctrine']['auditing_services']]; |
||
104 | } elseif (!\array_key_exists('auditing_services', $v['doctrine']) || !\is_array($v['doctrine']['auditing_services'])) { |
||
105 | $v['doctrine']['auditing_services'] = ['doctrine.orm.default_entity_manager']; |
||
106 | } |
||
107 | |||
108 | // "viewer" is disabled by default |
||
109 | if (!\array_key_exists('viewer', $v['doctrine']) || !\is_bool($v['doctrine']['viewer'])) { |
||
110 | $v['doctrine']['viewer'] = false; |
||
111 | } |
||
112 | |||
113 | // "storage_mapper" is null by default |
||
114 | if (!\array_key_exists('storage_mapper', $v['doctrine']) || !\is_string($v['doctrine']['storage_mapper'])) { |
||
115 | $v['doctrine']['storage_mapper'] = null; |
||
116 | } |
||
117 | |||
118 | return $v; |
||
119 | }) |
||
120 | ->end() |
||
121 | ; |
||
124 |