| Conditions | 2 |
| Paths | 1 |
| Total Lines | 68 |
| Code Lines | 60 |
| 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 |
||
| 37 | public function getConfigTreeBuilder() |
||
| 38 | { |
||
| 39 | $treeBuilder = new TreeBuilder(); |
||
| 40 | $treeBuilder->root('swp_settings') |
||
| 41 | ->children() |
||
| 42 | ->scalarNode('cache_service')->defaultNull()->info('A service implementing Psr\Cache\CacheItemPoolInterface')->end() |
||
| 43 | ->integerNode('cache_lifetime')->defaultValue(3600)->end() |
||
| 44 | ->arrayNode('persistence') |
||
| 45 | ->addDefaultsIfNotSet() |
||
| 46 | ->children() |
||
| 47 | ->arrayNode('orm') |
||
| 48 | ->addDefaultsIfNotSet() |
||
| 49 | ->canBeEnabled() |
||
| 50 | ->children() |
||
| 51 | ->arrayNode('classes') |
||
| 52 | ->addDefaultsIfNotSet() |
||
| 53 | ->children() |
||
| 54 | ->arrayNode('settings') |
||
| 55 | ->addDefaultsIfNotSet() |
||
| 56 | ->children() |
||
| 57 | ->scalarNode('model')->cannotBeEmpty()->defaultValue(Settings::class)->end() |
||
| 58 | ->scalarNode('repository')->defaultValue(SettingsRepository::class)->end() |
||
| 59 | ->scalarNode('factory')->defaultValue(Factory::class)->end() |
||
| 60 | ->scalarNode('interface')->defaultValue(SettingsInterface::class)->end() |
||
| 61 | ->scalarNode('object_manager_name')->defaultValue(null)->end() |
||
| 62 | ->end() |
||
| 63 | ->end() |
||
| 64 | ->end() // classes |
||
| 65 | ->end() // array node |
||
| 66 | ->end() |
||
| 67 | ->end() |
||
| 68 | ->end() |
||
| 69 | ->end() |
||
| 70 | ->arrayNode('settings') |
||
| 71 | ->useAttributeAsKey('settings') |
||
| 72 | ->prototype('array') |
||
| 73 | ->addDefaultsIfNotSet() |
||
| 74 | ->children() |
||
| 75 | ->scalarNode('scope')->defaultValue('global')->end() |
||
| 76 | ->scalarNode('value') |
||
| 77 | ->beforeNormalization() |
||
| 78 | ->ifArray() |
||
| 79 | ->then(function ($value) { |
||
| 80 | return json_encode($value); |
||
| 81 | }) |
||
| 82 | ->end() |
||
| 83 | ->defaultValue(null) |
||
| 84 | ->end() |
||
| 85 | ->scalarNode('type') |
||
| 86 | ->defaultValue('string') |
||
| 87 | ->validate() |
||
| 88 | ->always(function ($v) { |
||
| 89 | if (!in_array($v, ['string', 'array'])) { |
||
| 90 | throw new InvalidTypeException(); |
||
| 91 | } |
||
| 92 | |||
| 93 | return $v; |
||
| 94 | }) |
||
| 95 | ->end() |
||
| 96 | ->end() |
||
| 97 | ->end() |
||
| 98 | ->end() |
||
| 99 | ->end() |
||
| 100 | ->end() |
||
| 101 | ; |
||
| 102 | |||
| 103 | return $treeBuilder; |
||
| 104 | } |
||
| 105 | } |
||
| 106 |