| Conditions | 1 |
| Paths | 1 |
| Total Lines | 69 |
| 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 |
||
| 26 | public function getConfigTreeBuilder() |
||
| 27 | { |
||
| 28 | $treeBuilder = new TreeBuilder(); |
||
| 29 | $rootNode = $treeBuilder->root('open_conext_user_lifecycle_api_client'); |
||
| 30 | |||
| 31 | $rootNode |
||
| 32 | ->children() |
||
| 33 | ->booleanNode('enabled') |
||
| 34 | ->isRequired() |
||
| 35 | ->info('Give user the option to download their data') |
||
| 36 | ->end() |
||
| 37 | ->arrayNode('http_client') |
||
| 38 | ->children() |
||
| 39 | ->scalarNode('base_url') |
||
| 40 | ->info('The base URL of the user lifecycle API host') |
||
| 41 | ->isRequired() |
||
| 42 | ->cannotBeEmpty() |
||
| 43 | ->validate() |
||
| 44 | ->ifTrue(function ($baseUrl) { |
||
| 45 | return !is_string($baseUrl); |
||
| 46 | }) |
||
| 47 | ->thenInvalid('The user lifecycle API base URL should be a string') |
||
| 48 | ->end() |
||
| 49 | ->validate() |
||
| 50 | ->ifTrue(function ($baseUrl) { |
||
| 51 | return !filter_var($baseUrl, FILTER_VALIDATE_URL); |
||
| 52 | }) |
||
| 53 | ->thenInvalid('The user lifecycle base URL should be a valid URL') |
||
| 54 | ->end() |
||
| 55 | ->validate() |
||
| 56 | ->ifTrue(function ($baseUrl) { |
||
| 57 | $path = parse_url($baseUrl, PHP_URL_PATH); |
||
| 58 | |||
| 59 | return $path[strlen($path)-1] !== '/'; |
||
| 60 | }) |
||
| 61 | ->thenInvalid('The user lifecycle base URL must end in a forward slash') |
||
| 62 | ->end() |
||
| 63 | ->end() |
||
| 64 | ->booleanNode('verify_ssl') |
||
| 65 | ->defaultTrue() |
||
| 66 | ->end() |
||
| 67 | ->scalarNode('username') |
||
| 68 | ->info('The username of the API user') |
||
| 69 | ->isRequired() |
||
| 70 | ->cannotBeEmpty() |
||
| 71 | ->validate() |
||
| 72 | ->ifTrue(function ($username) { |
||
| 73 | return !is_string($username); |
||
| 74 | }) |
||
| 75 | ->thenInvalid('The user lifecycle username should be a string') |
||
| 76 | ->end() |
||
| 77 | ->end() |
||
| 78 | ->scalarNode('password') |
||
| 79 | ->info('The password of the API user') |
||
| 80 | ->isRequired() |
||
| 81 | ->cannotBeEmpty() |
||
| 82 | ->validate() |
||
| 83 | ->ifTrue(function ($password) { |
||
| 84 | return !is_string($password); |
||
| 85 | }) |
||
| 86 | ->thenInvalid('The user lifecycle password should be a string') |
||
| 87 | ->end() |
||
| 88 | ->end() |
||
| 89 | ->end() |
||
| 90 | ->end() |
||
| 91 | ->end(); |
||
| 92 | |||
| 93 | return $treeBuilder; |
||
| 94 | } |
||
| 95 | } |
||
| 96 |