Conditions | 6 |
Paths | 1 |
Total Lines | 66 |
Code Lines | 50 |
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 |
||
15 | public function getConfigTreeBuilder() |
||
16 | { |
||
17 | $treeBuilder = new Definition\Builder\TreeBuilder('bicycle_tesseract_bridge'); |
||
18 | |||
19 | $treeBuilder |
||
20 | ->getRootNode() |
||
21 | ->children() |
||
22 | ->arrayNode('integrations') |
||
23 | ->isRequired() |
||
24 | ->children() |
||
25 | ->arrayNode('cli') |
||
26 | ->canBeEnabled() |
||
27 | ->children() |
||
28 | ->scalarNode('path') |
||
29 | ->defaultNull() |
||
30 | ->example('tesseract') |
||
31 | ->info('Path to tesseract cli binary. ' . |
||
32 | 'It could be just "tesseract" in case binary in PATH or relative/absolute') |
||
33 | ->end() |
||
34 | ->end() |
||
35 | ->end() |
||
36 | ->arrayNode('ffi') |
||
37 | ->canBeEnabled() |
||
38 | ->children() |
||
39 | ->scalarNode('path') |
||
40 | ->defaultNull() |
||
41 | ->example('libtesseract.so.4') |
||
42 | ->info('Path to tesseract shared library. It could be' . |
||
43 | 'just "libtesseract.so.4" in case library is in PATH or relative/absolute') |
||
44 | ->end() |
||
45 | ->end() |
||
46 | ->end() |
||
47 | ->end() |
||
48 | ->validate() |
||
49 | ->ifTrue(static function (array $integrations) { |
||
50 | $enabledIntegrationsCount = 0; |
||
51 | /** @var array $integration */ |
||
52 | foreach ($integrations as $integration) { |
||
53 | /** @psalm-suppress MixedArrayAccess */ |
||
54 | if ($integration['enabled']) { |
||
55 | ++$enabledIntegrationsCount; |
||
56 | } |
||
57 | } |
||
58 | |||
59 | return 0 === $enabledIntegrationsCount; |
||
60 | }) |
||
61 | ->thenInvalid('At least one integration must be enabled') |
||
62 | ->end() |
||
63 | ->validate() |
||
64 | ->ifTrue(static function (array $integrations) { |
||
65 | /** @var array $integration */ |
||
66 | foreach ($integrations as $integration) { |
||
67 | /** @psalm-suppress MixedArrayAccess */ |
||
68 | if ($integration['enabled'] && empty($integration['path'])) { |
||
69 | return true; |
||
70 | } |
||
71 | } |
||
72 | |||
73 | return false; |
||
74 | }) |
||
75 | ->thenInvalid('Enabled integrations must have configured path') |
||
76 | ->end() |
||
77 | ->end() |
||
78 | ->end(); |
||
79 | |||
80 | return $treeBuilder; |
||
81 | } |
||
83 |