| Conditions | 3 |
| Paths | 1 |
| Total Lines | 67 |
| Code Lines | 58 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| Bugs | 1 | Features | 2 |
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 |
||
| 27 | public function getConfigTreeBuilder() |
||
| 28 | { |
||
| 29 | $treeBuilder = new TreeBuilder(); |
||
| 30 | $rootNode = $treeBuilder->root('api_platform'); |
||
| 31 | |||
| 32 | $rootNode |
||
| 33 | ->children() |
||
| 34 | ->scalarNode('title')->defaultValue('')->info('The title of the API.')->end() |
||
| 35 | ->scalarNode('description')->defaultValue('')->info('The description of the API.')->end() |
||
| 36 | ->arrayNode('supported_formats') |
||
| 37 | ->defaultValue(['jsonld' => ['mime_types' => ['application/ld+json']]]) |
||
| 38 | ->info('The list of enabled formats. The first one will be the default.') |
||
| 39 | ->normalizeKeys(false) |
||
| 40 | ->useAttributeAsKey('format') |
||
| 41 | ->beforeNormalization() |
||
| 42 | ->ifArray() |
||
| 43 | ->then(function ($v) { |
||
| 44 | foreach ($v as $format => $value) { |
||
| 45 | if (isset($value['mime_types'])) { |
||
| 46 | continue; |
||
| 47 | } |
||
| 48 | |||
| 49 | $v[$format] = ['mime_types' => $value]; |
||
| 50 | } |
||
| 51 | |||
| 52 | return $v; |
||
| 53 | }) |
||
| 54 | ->end() |
||
| 55 | ->prototype('array') |
||
| 56 | ->children() |
||
| 57 | ->arrayNode('mime_types')->prototype('scalar')->end()->end() |
||
| 58 | ->end() |
||
| 59 | ->end() |
||
| 60 | ->end() |
||
| 61 | ->arrayNode('routing') |
||
| 62 | ->addDefaultsIfNotSet() |
||
| 63 | ->children() |
||
| 64 | ->scalarNode('resource_path_generator')->defaultValue('api_platform.routing.resource_path_generator.underscore')->info('Specify the strategy to use for generating resource paths.')->end() |
||
| 65 | ->end() |
||
| 66 | ->end() |
||
| 67 | ->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end() |
||
| 68 | ->booleanNode('enable_fos_user')->defaultValue(false)->info('Enable the FOSUserBundle integration.')->end() |
||
| 69 | ->booleanNode('enable_nelmio_api_doc')->defaultTrue()->info('Enable the Nelmio Api doc integration.')->end() |
||
| 70 | ->arrayNode('collection') |
||
| 71 | ->addDefaultsIfNotSet() |
||
| 72 | ->children() |
||
| 73 | ->scalarNode('order')->defaultNull()->info('The default order of results.')->end() |
||
| 74 | ->scalarNode('order_parameter_name')->defaultValue('order')->cannotBeEmpty()->info('The name of the query parameter to order results.')->end() |
||
| 75 | ->arrayNode('pagination') |
||
| 76 | ->canBeDisabled() |
||
| 77 | ->addDefaultsIfNotSet() |
||
| 78 | ->children() |
||
| 79 | ->booleanNode('enabled')->defaultTrue()->info('To enable or disable pagination for all resource collections by default.')->end() |
||
| 80 | ->booleanNode('client_enabled')->defaultFalse()->info('To allow the client to enable or disable the pagination.')->end() |
||
| 81 | ->booleanNode('client_items_per_page')->defaultFalse()->info('To allow the client to set the number of items per page.')->end() |
||
| 82 | ->integerNode('items_per_page')->defaultValue(30)->info('The default number of items per page.')->end() |
||
| 83 | ->scalarNode('page_parameter_name')->defaultValue('page')->cannotBeEmpty()->info('The default name of the parameter handling the page number.')->end() |
||
| 84 | ->scalarNode('enabled_parameter_name')->defaultValue('pagination')->cannotBeEmpty()->info('The name of the query parameter to enable or disable pagination.')->end() |
||
| 85 | ->scalarNode('items_per_page_parameter_name')->defaultValue('itemsPerPage')->cannotBeEmpty()->info('The name of the query parameter to set the number of items per page.')->end() |
||
| 86 | ->end() |
||
| 87 | ->end() |
||
| 88 | ->end() |
||
| 89 | ->end() |
||
| 90 | ->end(); |
||
| 91 | |||
| 92 | return $treeBuilder; |
||
| 93 | } |
||
| 94 | } |
||
| 95 |