| Conditions | 5 |
| Paths | 1 |
| Total Lines | 73 |
| Code Lines | 59 |
| 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 |
||
| 20 | public function getConfigTreeBuilder() |
||
| 21 | { |
||
| 22 | $treeBuilder = new TreeBuilder(); |
||
| 23 | $rootNode = $treeBuilder->root('styleci'); |
||
| 24 | |||
| 25 | $validFixers = array_merge(Fixers::$valid, array_keys(Fixers::$aliases)); |
||
| 26 | |||
| 27 | $rootNode |
||
| 28 | ->children() |
||
| 29 | ->enumNode('preset') |
||
| 30 | ->isRequired() |
||
| 31 | ->values(array_merge(array_keys(Fixers::getPresets()), array(ConfigBridge::PRESET_NONE))) |
||
| 32 | ->end() |
||
| 33 | ->booleanNode('linting') |
||
| 34 | ->defaultTrue() |
||
| 35 | ->end() |
||
| 36 | ->arrayNode('enabled') |
||
| 37 | ->beforeNormalization() |
||
| 38 | ->ifString() |
||
| 39 | ->then(function ($v) { |
||
| 40 | return array($v); |
||
| 41 | }) |
||
| 42 | ->end() |
||
| 43 | ->prototype('scalar') |
||
| 44 | ->validate() |
||
| 45 | ->ifNotInArray($validFixers) |
||
| 46 | ->thenInvalid('Invalid enabled fixer %s.') |
||
| 47 | ->end() |
||
| 48 | ->end() |
||
| 49 | ->end() |
||
| 50 | ->arrayNode('disabled') |
||
| 51 | ->beforeNormalization() |
||
| 52 | ->ifString() |
||
| 53 | ->then(function ($v) { |
||
| 54 | return array($v); |
||
| 55 | }) |
||
| 56 | ->end() |
||
| 57 | ->prototype('scalar') |
||
| 58 | ->validate() |
||
| 59 | ->ifNotInArray($validFixers) |
||
| 60 | ->thenInvalid('Invalid disabled fixer %s.') |
||
| 61 | ->end() |
||
| 62 | ->end() |
||
| 63 | ->end() |
||
| 64 | ->append($this->getFinderConfigurationNode()) |
||
| 65 | ->booleanNode('risky') |
||
| 66 | ->defaultTrue() |
||
| 67 | ->end() |
||
| 68 | ->end() |
||
| 69 | ->validate() |
||
| 70 | ->ifTrue(function ($config) { |
||
| 71 | $presets = Fixers::getPresets(); |
||
| 72 | $enabledFixers = ConfigBridge::PRESET_NONE === $config['preset'] |
||
| 73 | ? $config['enabled'] |
||
| 74 | : array_merge($presets[$config['preset']], $config['enabled']); |
||
| 75 | $disabledFixers = $config['disabled']; |
||
| 76 | $fixers = array_diff($enabledFixers, $disabledFixers); |
||
| 77 | |||
| 78 | // See: https://github.com/StyleCI/Config/blob/f9747aba632aa4d272f212b5b9c9942234f4f074/src/Config.php#L549-L553 |
||
|
|
|||
| 79 | foreach (Fixers::$conflicts as $first => $second) { |
||
| 80 | if (in_array($first, $fixers, true) && in_array($second, $fixers, true)) { |
||
| 81 | return true; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | |||
| 85 | return false; |
||
| 86 | }) |
||
| 87 | ->thenInvalid('Conflicted fixers. Check conflicts definition.') |
||
| 88 | ->end() |
||
| 89 | ; |
||
| 90 | |||
| 91 | return $treeBuilder; |
||
| 92 | } |
||
| 93 | |||
| 143 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.