| Conditions | 1 |
| Paths | 1 |
| Total Lines | 95 |
| Code Lines | 84 |
| 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 |
||
| 36 | public function getConfigTreeBuilder() |
||
| 37 | { |
||
| 38 | $treeBuilder = new TreeBuilder(); |
||
| 39 | $rootNode = $treeBuilder->root('api_platform'); |
||
| 40 | |||
| 41 | $rootNode |
||
| 42 | ->children() |
||
| 43 | ->scalarNode('title')->defaultValue('')->info('The title of the API.')->end() |
||
| 44 | ->scalarNode('description')->defaultValue('')->info('The description of the API.')->end() |
||
| 45 | ->scalarNode('version')->defaultValue('0.0.0')->info('The version of the API.')->end() |
||
| 46 | ->scalarNode('default_operation_path_resolver')->defaultValue('api_platform.operation_path_resolver.underscore')->info('Specify the default operation path resolver to use for generating resources operations path.')->end() |
||
| 47 | ->scalarNode('name_converter')->defaultNull()->info('Specify a name converter to use.')->end() |
||
| 48 | ->arrayNode('eager_loading') |
||
| 49 | ->canBeDisabled() |
||
| 50 | ->addDefaultsIfNotSet() |
||
| 51 | ->children() |
||
| 52 | ->booleanNode('enabled')->defaultTrue()->info('To enable or disable eager loading')->end() |
||
| 53 | ->integerNode('max_joins')->defaultValue(30)->info('Max number of joined relations before EagerLoading throws a RuntimeException')->end() |
||
| 54 | ->booleanNode('force_eager')->defaultTrue()->info('Force join on every relation. If disabled, it will only join relations having the EAGER fetch mode.')->end() |
||
| 55 | ->end() |
||
| 56 | ->end() |
||
| 57 | ->booleanNode('enable_fos_user')->defaultValue(false)->info('Enable the FOSUserBundle integration.')->end() |
||
| 58 | ->booleanNode('enable_nelmio_api_doc')->defaultValue(false)->info('Enable the Nelmio Api doc integration.')->end() |
||
| 59 | ->booleanNode('enable_swagger')->defaultValue(true)->info('Enable the Swagger documentation and export.')->end() |
||
| 60 | ->booleanNode('enable_swagger_ui')->defaultValue(class_exists(TwigBundle::class))->info('Enable Swagger ui.')->end() |
||
| 61 | |||
| 62 | ->arrayNode('oauth') |
||
| 63 | ->canBeEnabled() |
||
| 64 | ->addDefaultsIfNotSet() |
||
| 65 | ->children() |
||
| 66 | ->booleanNode('enabled')->defaultFalse()->info('To enable or disable oauth')->end() |
||
| 67 | ->scalarNode('clientId')->defaultValue('')->info('The oauth client id.')->end() |
||
| 68 | ->scalarNode('clientSecret')->defaultValue('')->info('The oauth client secret.')->end() |
||
| 69 | ->scalarNode('type')->defaultValue('oauth2')->info('The oauth client secret.')->end() |
||
| 70 | ->scalarNode('flow')->defaultValue('application')->info('The oauth flow grant type.')->end() |
||
| 71 | ->scalarNode('tokenUrl')->defaultValue('/oauth/v2/token')->info('The oauth token url.')->end() |
||
| 72 | ->scalarNode('authorizationUrl')->defaultValue('/oauth/v2/auth')->info('The oauth authentication url.')->end() |
||
| 73 | ->arrayNode('scopes') |
||
| 74 | ->prototype('scalar')->end() |
||
| 75 | ->end() |
||
| 76 | ->end() |
||
| 77 | ->end() |
||
| 78 | |||
| 79 | ->arrayNode('collection') |
||
| 80 | ->addDefaultsIfNotSet() |
||
| 81 | ->children() |
||
| 82 | ->scalarNode('order')->defaultValue('ASC')->info('The default order of results.')->end() // Default ORDER is required for postgresql and mysql >= 5.7 when using LIMIT/OFFSET request |
||
| 83 | ->scalarNode('order_parameter_name')->defaultValue('order')->cannotBeEmpty()->info('The name of the query parameter to order results.')->end() |
||
| 84 | ->arrayNode('pagination') |
||
| 85 | ->canBeDisabled() |
||
| 86 | ->addDefaultsIfNotSet() |
||
| 87 | ->children() |
||
| 88 | ->booleanNode('enabled')->defaultTrue()->info('To enable or disable pagination for all resource collections by default.')->end() |
||
| 89 | ->booleanNode('client_enabled')->defaultFalse()->info('To allow the client to enable or disable the pagination.')->end() |
||
| 90 | ->booleanNode('client_items_per_page')->defaultFalse()->info('To allow the client to set the number of items per page.')->end() |
||
| 91 | ->integerNode('items_per_page')->defaultValue(30)->info('The default number of items per page.')->end() |
||
| 92 | ->integerNode('maximum_items_per_page')->defaultNull()->info('The maximum number of items per page.')->end() |
||
| 93 | ->scalarNode('page_parameter_name')->defaultValue('page')->cannotBeEmpty()->info('The default name of the parameter handling the page number.')->end() |
||
| 94 | ->scalarNode('enabled_parameter_name')->defaultValue('pagination')->cannotBeEmpty()->info('The name of the query parameter to enable or disable pagination.')->end() |
||
| 95 | ->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() |
||
| 96 | ->end() |
||
| 97 | ->end() |
||
| 98 | ->end() |
||
| 99 | ->end() |
||
| 100 | |||
| 101 | ->arrayNode('loader_paths') |
||
| 102 | ->addDefaultsIfNotSet() |
||
| 103 | ->children() |
||
| 104 | ->arrayNode('annotation') |
||
| 105 | ->prototype('scalar')->end() |
||
| 106 | ->end() |
||
| 107 | ->arrayNode('yaml') |
||
| 108 | ->prototype('scalar')->end() |
||
| 109 | ->end() |
||
| 110 | ->arrayNode('xml') |
||
| 111 | ->prototype('scalar')->end() |
||
| 112 | ->end() |
||
| 113 | ->end() |
||
| 114 | ->end() |
||
| 115 | ->end(); |
||
| 116 | |||
| 117 | $this->addExceptionToStatusSection($rootNode); |
||
| 118 | |||
| 119 | $this->addFormatSection($rootNode, 'formats', [ |
||
| 120 | 'jsonld' => ['mime_types' => ['application/ld+json']], |
||
| 121 | 'json' => ['mime_types' => ['application/json']], // Swagger support |
||
| 122 | 'html' => ['mime_types' => ['text/html']], // Swagger UI support |
||
| 123 | ]); |
||
| 124 | $this->addFormatSection($rootNode, 'error_formats', [ |
||
| 125 | 'jsonproblem' => ['mime_types' => ['application/problem+json']], |
||
| 126 | 'jsonld' => ['mime_types' => ['application/ld+json']], |
||
| 127 | ]); |
||
| 128 | |||
| 129 | return $treeBuilder; |
||
| 130 | } |
||
| 131 | |||
| 223 |