| Conditions | 7 |
| Paths | 1 |
| Total Lines | 80 |
| Code Lines | 63 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 36 |
| CRAP Score | 7.5034 |
| Changes | 3 | ||
| Bugs | 1 | Features | 1 |
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 |
||
| 20 | 4 | public function getConfigTreeBuilder() |
|
| 21 | { |
||
| 22 | 4 | $treeBuilder = new TreeBuilder(); |
|
| 23 | |||
| 24 | 4 | $rootNode = $treeBuilder->root('run_open_code_traitor'); |
|
| 25 | |||
| 26 | $rootNode |
||
| 27 | 4 | ->addDefaultsIfNotSet() |
|
| 28 | 4 | ->children() |
|
| 29 | 4 | ->booleanNode('use_common_traits') |
|
| 30 | 4 | ->defaultFalse() |
|
| 31 | 4 | ->info('For sake of productivity, some of the common Symfony and vendor traits, as well as traits from this library, can be automatically added to "inject" definition.') |
|
| 32 | 4 | ->end() |
|
| 33 | 4 | ->arrayNode('inject') |
|
| 34 | 4 | ->useAttributeAsKey('trait') |
|
| 35 | 4 | ->prototype('array') |
|
| 36 | 4 | ->validate() |
|
| 37 | 4 | ->ifTrue(function($value) { |
|
| 38 | |||
| 39 | if (!is_array($value) || 2 !== count($value)) { |
||
| 40 | 1 | return true; |
|
| 41 | } |
||
| 42 | |||
| 43 | if (!is_string($value[0])) { |
||
| 44 | return true; |
||
| 45 | } |
||
| 46 | |||
| 47 | if (!is_array($value[1])) { |
||
| 48 | return true; |
||
| 49 | } |
||
| 50 | |||
| 51 | foreach ($value[1] as $arg) { |
||
| 52 | |||
| 53 | if (!is_string($arg)) { |
||
| 54 | return true; |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | return false; |
||
| 59 | 4 | }) |
|
| 60 | 4 | ->thenInvalid('Expected proper setter injection definition.') |
|
| 61 | 4 | ->end() |
|
| 62 | 4 | ->prototype('variable') |
|
| 63 | 4 | ->end() |
|
| 64 | 4 | ->end() |
|
| 65 | 4 | ->end() |
|
| 66 | 4 | ->arrayNode('filters') |
|
| 67 | 4 | ->info('Analyse services for injection which matches filter criteria.') |
|
| 68 | 4 | ->children() |
|
| 69 | 4 | ->arrayNode('tags') |
|
| 70 | 4 | ->prototype('scalar') |
|
| 71 | 4 | ->end() |
|
| 72 | 4 | ->end() |
|
| 73 | 4 | ->arrayNode('namespaces') |
|
| 74 | 4 | ->prototype('scalar') |
|
| 75 | 4 | ->end() |
|
| 76 | 4 | ->end() |
|
| 77 | 4 | ->end() |
|
| 78 | 4 | ->end() |
|
| 79 | ->arrayNode('exclude') |
||
| 80 | 4 | ->info('Exclude services from injection which matches filter criteria.') |
|
| 81 | ->children() |
||
| 82 | ->arrayNode('services') |
||
| 83 | ->prototype('scalar') |
||
| 84 | ->end() |
||
| 85 | ->end() |
||
| 86 | ->arrayNode('namespaces') |
||
| 87 | ->prototype('scalar') |
||
| 88 | ->end() |
||
| 89 | ->end() |
||
| 90 | ->arrayNode('classes') |
||
| 91 | ->prototype('scalar') |
||
| 92 | ->end() |
||
| 93 | ->end() |
||
| 94 | ->end() |
||
| 95 | ->end() |
||
| 96 | ->end(); |
||
| 97 | |||
| 98 | return $treeBuilder; |
||
| 99 | } |
||
| 100 | } |
||
| 101 |