| Conditions | 6 |
| Paths | 1 |
| Total Lines | 57 |
| Code Lines | 45 |
| 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 |
||
| 34 | private function getPermissionsNode() |
||
| 35 | { |
||
| 36 | $isString = function ($value) { |
||
| 37 | return is_string($value); |
||
| 38 | }; |
||
| 39 | $isNotCollection = function ($value) { |
||
| 40 | if (!is_array($value)) { |
||
| 41 | return true; |
||
| 42 | } |
||
| 43 | |||
| 44 | if (isset($value[0]) && is_string($value[0]) && isset($value[1]) && is_string($value[1])) { |
||
|
|
|||
| 45 | return true; |
||
| 46 | } |
||
| 47 | |||
| 48 | return false; |
||
| 49 | }; |
||
| 50 | $toArray = function ($value) { |
||
| 51 | return [$value]; |
||
| 52 | }; |
||
| 53 | |||
| 54 | ($node = $this->root('permissions')) |
||
| 55 | ->prototype('array') |
||
| 56 | ->children() |
||
| 57 | ->arrayNode('attributes') |
||
| 58 | ->info('Matching attribute(s). Empty means all attributes.') |
||
| 59 | ->prototype('scalar')->end() |
||
| 60 | ->beforeNormalization() |
||
| 61 | ->ifTrue($isString)->then($toArray) |
||
| 62 | ->end() |
||
| 63 | ->end() |
||
| 64 | ->arrayNode('subjects') |
||
| 65 | ->info('Matching subject(s) types. Can be either classes, interfaces or types. Empty means all subjects.') |
||
| 66 | ->prototype('scalar')->end() |
||
| 67 | ->beforeNormalization() |
||
| 68 | ->ifTrue($isString)->then($toArray) |
||
| 69 | ->end() |
||
| 70 | ->end() |
||
| 71 | ->arrayNode('roles') |
||
| 72 | ->info('Required role(s) for these attributes & subjects.') |
||
| 73 | ->prototype('scalar')->end() |
||
| 74 | ->beforeNormalization() |
||
| 75 | ->ifTrue($isString)->then($toArray) |
||
| 76 | ->end() |
||
| 77 | ->end() |
||
| 78 | ->arrayNode('callables') |
||
| 79 | ->info('Callables that will verify access.') |
||
| 80 | ->prototype('variable')->end() |
||
| 81 | ->beforeNormalization() |
||
| 82 | ->ifTrue($isNotCollection)->then($toArray) |
||
| 83 | ->end() |
||
| 84 | ->end() |
||
| 85 | ->end() |
||
| 86 | ->end() |
||
| 87 | ; |
||
| 88 | |||
| 89 | return $node; |
||
| 90 | } |
||
| 91 | |||
| 102 |