| Conditions | 12 |
| Paths | 1 |
| Total Lines | 111 |
| Code Lines | 91 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 92 |
| CRAP Score | 12 |
| Changes | 10 | ||
| Bugs | 2 | Features | 3 |
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 |
||
| 42 | 14 | public function getConfigTreeBuilder() |
|
| 43 | { |
||
| 44 | 14 | $treeBuilder = new TreeBuilder(); |
|
| 45 | 14 | $rootNode = $treeBuilder->root('httplug'); |
|
| 46 | |||
| 47 | 14 | $this->configureClients($rootNode); |
|
| 48 | 14 | $this->configurePlugins($rootNode); |
|
| 49 | |||
| 50 | $rootNode |
||
| 51 | 14 | ->validate() |
|
| 52 | ->ifTrue(function ($v) { |
||
| 53 | 12 | return !empty($v['classes']['client']) |
|
| 54 | 12 | || !empty($v['classes']['message_factory']) |
|
| 55 | 9 | || !empty($v['classes']['uri_factory']) |
|
| 56 | 12 | || !empty($v['classes']['stream_factory']); |
|
| 57 | 14 | }) |
|
| 58 | ->then(function ($v) { |
||
| 59 | 3 | foreach ($v['classes'] as $key => $class) { |
|
| 60 | 3 | if (null !== $class && !class_exists($class)) { |
|
| 61 | 1 | throw new InvalidConfigurationException(sprintf( |
|
| 62 | 1 | 'Class %s specified for httplug.classes.%s does not exist.', |
|
| 63 | 1 | $class, |
|
| 64 | $key |
||
| 65 | 1 | )); |
|
| 66 | } |
||
| 67 | 2 | } |
|
| 68 | |||
| 69 | 2 | return $v; |
|
| 70 | 14 | }) |
|
| 71 | 14 | ->end() |
|
| 72 | 14 | ->beforeNormalization() |
|
| 73 | ->ifTrue(function ($v) { |
||
| 74 | 14 | return is_array($v) && array_key_exists('toolbar', $v) && is_array($v['toolbar']); |
|
| 75 | 14 | }) |
|
| 76 | ->then(function ($v) { |
||
| 77 | 4 | if (array_key_exists('profiling', $v)) { |
|
| 78 | 1 | throw new InvalidConfigurationException('Can\'t configure both "toolbar" and "profiling" section. The "toolbar" config is deprecated as of version 1.3.0, please only use "profiling".'); |
|
| 79 | } |
||
| 80 | |||
| 81 | 3 | @trigger_error('"httplug.toolbar" config is deprecated since version 1.3 and will be removed in 2.0. Use "httplug.profiling" instead.', E_USER_DEPRECATED); |
|
|
|
|||
| 82 | |||
| 83 | 3 | if (array_key_exists('enabled', $v['toolbar']) && 'auto' === $v['toolbar']['enabled']) { |
|
| 84 | 1 | @trigger_error('"auto" value in "httplug.toolbar" config is deprecated since version 1.3 and will be removed in 2.0. Use a boolean value instead.', E_USER_DEPRECATED); |
|
|
1 ignored issue
–
show
|
|||
| 85 | 1 | $v['toolbar']['enabled'] = $this->debug; |
|
| 86 | 1 | } |
|
| 87 | |||
| 88 | 3 | $v['profiling'] = $v['toolbar']; |
|
| 89 | |||
| 90 | 3 | unset($v['toolbar']); |
|
| 91 | |||
| 92 | 3 | return $v; |
|
| 93 | 14 | }) |
|
| 94 | 14 | ->end() |
|
| 95 | 14 | ->fixXmlConfig('client') |
|
| 96 | 14 | ->children() |
|
| 97 | 14 | ->arrayNode('main_alias') |
|
| 98 | 14 | ->addDefaultsIfNotSet() |
|
| 99 | 14 | ->info('Configure which service the main alias point to.') |
|
| 100 | 14 | ->children() |
|
| 101 | 14 | ->scalarNode('client')->defaultValue('httplug.client.default')->end() |
|
| 102 | 14 | ->scalarNode('message_factory')->defaultValue('httplug.message_factory.default')->end() |
|
| 103 | 14 | ->scalarNode('uri_factory')->defaultValue('httplug.uri_factory.default')->end() |
|
| 104 | 14 | ->scalarNode('stream_factory')->defaultValue('httplug.stream_factory.default')->end() |
|
| 105 | 14 | ->end() |
|
| 106 | 14 | ->end() |
|
| 107 | 14 | ->arrayNode('classes') |
|
| 108 | 14 | ->addDefaultsIfNotSet() |
|
| 109 | 14 | ->info('Overwrite a service class instead of using the discovery mechanism.') |
|
| 110 | 14 | ->children() |
|
| 111 | 14 | ->scalarNode('client')->defaultNull()->end() |
|
| 112 | 14 | ->scalarNode('message_factory')->defaultNull()->end() |
|
| 113 | 14 | ->scalarNode('uri_factory')->defaultNull()->end() |
|
| 114 | 14 | ->scalarNode('stream_factory')->defaultNull()->end() |
|
| 115 | 14 | ->end() |
|
| 116 | 14 | ->end() |
|
| 117 | 14 | ->arrayNode('profiling') |
|
| 118 | 14 | ->addDefaultsIfNotSet() |
|
| 119 | 14 | ->treatFalseLike(['enabled' => false]) |
|
| 120 | 14 | ->treatTrueLike(['enabled' => true]) |
|
| 121 | 14 | ->treatNullLike(['enabled' => $this->debug]) |
|
| 122 | 14 | ->info('Extend the debug profiler with information about requests.') |
|
| 123 | 14 | ->children() |
|
| 124 | 14 | ->booleanNode('enabled') |
|
| 125 | 14 | ->info('Turn the toolbar on or off. Defaults to kernel debug mode.') |
|
| 126 | 14 | ->defaultValue($this->debug) |
|
| 127 | 14 | ->end() |
|
| 128 | 14 | ->scalarNode('formatter')->defaultNull()->end() |
|
| 129 | 14 | ->integerNode('captured_body_length') |
|
| 130 | 14 | ->defaultValue(0) |
|
| 131 | 14 | ->info('Limit long HTTP message bodies to x characters. If set to 0 we do not read the message body. Only available with the default formatter (FullHttpMessageFormatter).') |
|
| 132 | 14 | ->end() |
|
| 133 | 14 | ->end() |
|
| 134 | 14 | ->end() |
|
| 135 | 14 | ->arrayNode('discovery') |
|
| 136 | 14 | ->addDefaultsIfNotSet() |
|
| 137 | 14 | ->info('Control what clients should be found by the discovery.') |
|
| 138 | 14 | ->children() |
|
| 139 | 14 | ->scalarNode('client') |
|
| 140 | 14 | ->defaultValue('auto') |
|
| 141 | 14 | ->info('Set to "auto" to see auto discovered client in the web profiler. If provided a service id for a client then this client will be found by auto discovery.') |
|
| 142 | 14 | ->end() |
|
| 143 | 14 | ->scalarNode('async_client') |
|
| 144 | 14 | ->defaultNull() |
|
| 145 | 14 | ->info('Set to "auto" to see auto discovered client in the web profiler. If provided a service id for a client then this client will be found by auto discovery.') |
|
| 146 | 14 | ->end() |
|
| 147 | 14 | ->end() |
|
| 148 | 14 | ->end() |
|
| 149 | 14 | ->end(); |
|
| 150 | |||
| 151 | 14 | return $treeBuilder; |
|
| 152 | } |
||
| 153 | |||
| 390 |
If you suppress an error, we recommend checking for the error condition explicitly: