| Conditions | 1 |
| Paths | 1 |
| Total Lines | 62 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 104 | private function addExceptionsSection(ArrayNodeDefinition $rootNode): void |
||
| 105 | { |
||
| 106 | $rootNode->children() |
||
| 107 | ->arrayNode('exception_handling') |
||
| 108 | ->treatTrueLike(['enabled' => true]) |
||
| 109 | ->treatFalseLike(['enabled' => false]) |
||
| 110 | ->treatNullLike(['enabled' => null]) |
||
| 111 | ->addDefaultsIfNotSet() |
||
| 112 | ->children() |
||
| 113 | ->booleanNode('enabled') |
||
| 114 | ->info( |
||
| 115 | 'Set to true to enable the new serialization-based exception handling.'.PHP_EOL. |
||
| 116 | 'Set to false to disable exception handling provided by this bundle.'.PHP_EOL. |
||
| 117 | 'Set to null to keep using the deprecated exception JSON response builder.' |
||
| 118 | ) |
||
| 119 | ->defaultNull() |
||
| 120 | ->validate() |
||
| 121 | ->ifNull() |
||
| 122 | ->then(function ($value) { |
||
| 123 | trigger_deprecation( |
||
| 124 | self::BUNDLE_NAME, |
||
| 125 | '1.3', |
||
| 126 | 'Setting the "nijens_openapi.exceptions.enabled" option to "null" is deprecated. It will default to "true" as of version 2.0.' |
||
| 127 | ); |
||
| 128 | |||
| 129 | return $value; |
||
| 130 | }) |
||
| 131 | ->end() |
||
| 132 | ->end() |
||
| 133 | ->arrayNode('exceptions') |
||
| 134 | ->useAttributeAsKey('class') |
||
| 135 | ->arrayPrototype() |
||
| 136 | ->children() |
||
| 137 | ->scalarNode('class') |
||
| 138 | ->info('The fully qualified class name of the exception.') |
||
| 139 | ->cannotBeEmpty() |
||
| 140 | ->end() |
||
| 141 | ->integerNode('status_code') |
||
| 142 | ->info('The HTTP status code that must be sent when this exception occurs.') |
||
| 143 | ->isRequired() |
||
| 144 | ->min(100) |
||
| 145 | ->max(999) |
||
| 146 | ->end() |
||
| 147 | ->scalarNode('type_uri') |
||
| 148 | ->info('The RFC 7807 URI reference that identifies the problem type. It will be sent with the response.') |
||
| 149 | ->cannotBeEmpty() |
||
| 150 | ->defaultValue('about:blank') |
||
| 151 | ->end() |
||
| 152 | ->scalarNode('title') |
||
| 153 | ->info('The RFC 7807 title that summarizes the problem type in human-readable language. It will be sent with the response.') |
||
| 154 | ->cannotBeEmpty() |
||
| 155 | ->defaultValue('An error occurred.') |
||
| 156 | ->end() |
||
| 157 | ->booleanNode('add_instance_uri') |
||
| 158 | ->defaultFalse() |
||
| 159 | ->end() |
||
| 160 | ->end() |
||
| 161 | ->end() |
||
| 162 | ->end() |
||
| 163 | ->end() |
||
| 164 | ->end() |
||
| 165 | ->end(); |
||
| 166 | } |
||
| 168 |