Conditions | 10 |
Paths | 1 |
Total Lines | 64 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | 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 |
||
17 | public function configureAnonymizer(ArrayNodeDefinition $node) |
||
18 | { |
||
19 | $node |
||
20 | ->children() |
||
21 | ->arrayNode('defaults') |
||
22 | ->scalarPrototype()->end() |
||
23 | ->end() |
||
|
|||
24 | ->arrayNode('tables') |
||
25 | ->arrayPrototype() |
||
26 | ->children() |
||
27 | ->booleanNode('truncate')->defaultFalse()->end() |
||
28 | ->arrayNode('primary_key') |
||
29 | ->scalarPrototype()->end() |
||
30 | ->end() |
||
31 | ->arrayNode('fields') |
||
32 | ->arrayPrototype() |
||
33 | ->variablePrototype()->end() |
||
34 | ->end() |
||
35 | ->end() // fields |
||
36 | ->end() |
||
37 | ->end() |
||
38 | ->end() // tables |
||
39 | ->end() |
||
40 | ->beforeNormalization() |
||
41 | // Pass default table configuration to field configuration. |
||
42 | // defaults: |
||
43 | // locale: fr_FR |
||
44 | // seed: seed_key |
||
45 | // tables: |
||
46 | // user: |
||
47 | // fields: |
||
48 | // name: |
||
49 | // generator: first_name |
||
50 | // # locale "fr_FR" will be set here. |
||
51 | // # seed "seed_key" will be set here. |
||
52 | // lastname: |
||
53 | // generator: first_name |
||
54 | // locale: en_EN |
||
55 | // seed: lastname_seed_key |
||
56 | // # locale "en_EN" overwrites default value fr_FR. |
||
57 | // # seed "lastname_seed_key" overwrites default value "seed_key". |
||
58 | ->ifTrue(static function ($v) { |
||
59 | return \is_array($v) && \array_key_exists('defaults', $v) && \is_array($v['defaults']); |
||
60 | }) |
||
61 | ->then(static function ($c) { |
||
62 | if (isset($c['tables'])) { |
||
63 | foreach ($c['tables'] as &$tableConfig) { |
||
64 | if ($tableConfig['fields']) { |
||
65 | foreach ($tableConfig['fields'] as &$fieldConfig) { |
||
66 | if (isset($c['defaults'])) { |
||
67 | foreach ($c['defaults'] as $defaultKey => $defaultValue) { |
||
68 | if (!\array_key_exists($defaultKey, $fieldConfig)) { |
||
69 | $fieldConfig[$defaultKey] = $defaultValue; |
||
70 | } |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | } |
||
77 | |||
78 | return $c; |
||
79 | }) |
||
80 | ->end() |
||
81 | ; |
||
84 |