| Conditions | 4 |
| Paths | 1 |
| Total Lines | 67 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| 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 |
||
| 19 | public function getConfigTreeBuilder() |
||
| 20 | { |
||
| 21 | $treeBuilder = new TreeBuilder(); |
||
| 22 | $rootNode = $treeBuilder->root('styleci'); |
||
| 23 | |||
| 24 | $validFixers = array_merge(Fixers::$valid, array_keys(Fixers::$aliases)); |
||
| 25 | |||
| 26 | $rootNode |
||
| 27 | ->children() |
||
| 28 | ->enumNode('preset') |
||
| 29 | ->isRequired() |
||
| 30 | ->values(array_keys(Fixers::getPresets())) |
||
| 31 | ->end() |
||
| 32 | ->booleanNode('linting') |
||
| 33 | ->defaultTrue() |
||
| 34 | ->end() |
||
| 35 | ->arrayNode('enabled') |
||
| 36 | ->beforeNormalization() |
||
| 37 | ->ifString() |
||
| 38 | ->then(function ($v) { return array($v); }) |
||
| 39 | ->end() |
||
| 40 | ->prototype('scalar') |
||
| 41 | ->validate() |
||
| 42 | ->ifNotInArray($validFixers) |
||
| 43 | ->thenInvalid('Invalid enabled fixer %s.') |
||
| 44 | ->end() |
||
| 45 | ->end() |
||
| 46 | ->end() |
||
| 47 | ->arrayNode('disabled') |
||
| 48 | ->beforeNormalization() |
||
| 49 | ->ifString() |
||
| 50 | ->then(function ($v) { return array($v); }) |
||
| 51 | ->end() |
||
| 52 | ->prototype('scalar') |
||
| 53 | ->validate() |
||
| 54 | ->ifNotInArray($validFixers) |
||
| 55 | ->thenInvalid('Invalid disabled fixer %s.') |
||
| 56 | ->end() |
||
| 57 | ->end() |
||
| 58 | ->end() |
||
| 59 | ->append($this->getFinderConfigurationNode()) |
||
| 60 | ->booleanNode('risky') |
||
| 61 | ->defaultTrue() |
||
| 62 | ->end() |
||
| 63 | ->end() |
||
| 64 | ->validate() |
||
| 65 | ->ifTrue(function ($config) { |
||
| 66 | $presets = Fixers::getPresets(); |
||
| 67 | $enabledFixers = array_merge($presets[$config['preset']], $config['enabled']); |
||
| 68 | $disabledFixers = $config['disabled']; |
||
| 69 | $fixers = array_diff($enabledFixers, $disabledFixers); |
||
| 70 | |||
| 71 | // See: https://github.com/StyleCI/Config/blob/f9747aba632aa4d272f212b5b9c9942234f4f074/src/Config.php#L549-L553 |
||
| 72 | foreach (Fixers::$conflicts as $first => $second) { |
||
| 73 | if (in_array($first, $fixers, true) && in_array($second, $fixers, true)) { |
||
| 74 | return true; |
||
| 75 | } |
||
| 76 | } |
||
| 77 | |||
| 78 | return false; |
||
| 79 | }) |
||
| 80 | ->thenInvalid('Conflicted fixers. Check conflicts definition.') |
||
| 81 | ->end() |
||
| 82 | ; |
||
| 83 | |||
| 84 | return $treeBuilder; |
||
| 85 | } |
||
| 86 | |||
| 136 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: