| Conditions | 1 |
| Paths | 1 |
| Total Lines | 124 |
| Code Lines | 111 |
| 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 | ->scalarNode('api_resources_directory')->defaultValue('Entity')->info('The name of the directory within the bundles that contains the api resources.')->end() |
||
| 49 | ->arrayNode('eager_loading') |
||
| 50 | ->canBeDisabled() |
||
| 51 | ->addDefaultsIfNotSet() |
||
| 52 | ->children() |
||
| 53 | ->booleanNode('enabled')->defaultTrue()->info('To enable or disable eager loading')->end() |
||
| 54 | ->booleanNode('fetch_partial')->defaultFalse()->info('Fetch only partial data according to serialization groups. If enabled, Doctrine ORM entities will not work as expected if any of the other fields are used.')->end() |
||
| 55 | ->integerNode('max_joins')->defaultValue(30)->info('Max number of joined relations before EagerLoading throws a RuntimeException')->end() |
||
| 56 | ->booleanNode('force_eager')->defaultTrue()->info('Force join on every relation. If disabled, it will only join relations having the EAGER fetch mode.')->end() |
||
| 57 | ->end() |
||
| 58 | ->end() |
||
| 59 | ->booleanNode('enable_fos_user')->defaultValue(false)->info('Enable the FOSUserBundle integration.')->end() |
||
| 60 | ->booleanNode('enable_nelmio_api_doc')->defaultValue(false)->info('Enable the Nelmio Api doc integration.')->end() |
||
| 61 | ->booleanNode('enable_swagger')->defaultValue(true)->info('Enable the Swagger documentation and export.')->end() |
||
| 62 | ->booleanNode('enable_swagger_ui')->defaultValue(class_exists(TwigBundle::class))->info('Enable Swagger ui.')->end() |
||
| 63 | |||
| 64 | ->arrayNode('oauth') |
||
| 65 | ->canBeEnabled() |
||
| 66 | ->addDefaultsIfNotSet() |
||
| 67 | ->children() |
||
| 68 | ->booleanNode('enabled')->defaultFalse()->info('To enable or disable oauth')->end() |
||
| 69 | ->scalarNode('clientId')->defaultValue('')->info('The oauth client id.')->end() |
||
| 70 | ->scalarNode('clientSecret')->defaultValue('')->info('The oauth client secret.')->end() |
||
| 71 | ->scalarNode('type')->defaultValue('oauth2')->info('The oauth client secret.')->end() |
||
| 72 | ->scalarNode('flow')->defaultValue('application')->info('The oauth flow grant type.')->end() |
||
| 73 | ->scalarNode('tokenUrl')->defaultValue('/oauth/v2/token')->info('The oauth token url.')->end() |
||
| 74 | ->scalarNode('authorizationUrl')->defaultValue('/oauth/v2/auth')->info('The oauth authentication url.')->end() |
||
| 75 | ->arrayNode('scopes') |
||
| 76 | ->prototype('scalar')->end() |
||
| 77 | ->end() |
||
| 78 | ->end() |
||
| 79 | ->end() |
||
| 80 | |||
| 81 | ->arrayNode('collection') |
||
| 82 | ->addDefaultsIfNotSet() |
||
| 83 | ->children() |
||
| 84 | ->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 |
||
| 85 | ->scalarNode('order_parameter_name')->defaultValue('order')->cannotBeEmpty()->info('The name of the query parameter to order results.')->end() |
||
| 86 | ->arrayNode('pagination') |
||
| 87 | ->canBeDisabled() |
||
| 88 | ->addDefaultsIfNotSet() |
||
| 89 | ->children() |
||
| 90 | ->booleanNode('enabled')->defaultTrue()->info('To enable or disable pagination for all resource collections by default.')->end() |
||
| 91 | ->booleanNode('client_enabled')->defaultFalse()->info('To allow the client to enable or disable the pagination.')->end() |
||
| 92 | ->booleanNode('client_items_per_page')->defaultFalse()->info('To allow the client to set the number of items per page.')->end() |
||
| 93 | ->integerNode('items_per_page')->defaultValue(30)->info('The default number of items per page.')->end() |
||
| 94 | ->integerNode('maximum_items_per_page')->defaultNull()->info('The maximum number of items per page.')->end() |
||
| 95 | ->scalarNode('page_parameter_name')->defaultValue('page')->cannotBeEmpty()->info('The default name of the parameter handling the page number.')->end() |
||
| 96 | ->scalarNode('enabled_parameter_name')->defaultValue('pagination')->cannotBeEmpty()->info('The name of the query parameter to enable or disable pagination.')->end() |
||
| 97 | ->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() |
||
| 98 | ->end() |
||
| 99 | ->end() |
||
| 100 | ->end() |
||
| 101 | ->end() |
||
| 102 | |||
| 103 | ->arrayNode('loader_paths') |
||
| 104 | ->addDefaultsIfNotSet() |
||
| 105 | ->children() |
||
| 106 | ->arrayNode('annotation') |
||
| 107 | ->prototype('scalar')->end() |
||
| 108 | ->end() |
||
| 109 | ->arrayNode('yaml') |
||
| 110 | ->prototype('scalar')->end() |
||
| 111 | ->end() |
||
| 112 | ->arrayNode('xml') |
||
| 113 | ->prototype('scalar')->end() |
||
| 114 | ->end() |
||
| 115 | ->end() |
||
| 116 | ->end() |
||
| 117 | |||
| 118 | ->arrayNode('http_cache') |
||
| 119 | ->addDefaultsIfNotSet() |
||
| 120 | ->children() |
||
| 121 | ->booleanNode('etag')->defaultTrue()->info('Automatically generate etags for API responses.')->end() |
||
| 122 | ->integerNode('max_age')->defaultNull()->info('Default value for the response max age.')->end() |
||
| 123 | ->integerNode('shared_max_age')->defaultNull()->info('Default value for the response shared (proxy) max age.')->end() |
||
| 124 | ->arrayNode('vary') |
||
| 125 | ->defaultValue(['Content-Type']) |
||
| 126 | ->prototype('scalar')->end() |
||
| 127 | ->info('Default values of the "Vary" HTTP header.') |
||
| 128 | ->end() |
||
| 129 | ->booleanNode('public')->defaultNull()->info('To make all responses public by default.')->end() |
||
| 130 | ->arrayNode('invalidation') |
||
| 131 | ->info('Enable the tags-based cache invalidation system.') |
||
| 132 | ->canBeEnabled() |
||
| 133 | ->children() |
||
| 134 | ->arrayNode('varnish_urls') |
||
| 135 | ->defaultValue([]) |
||
| 136 | ->prototype('scalar')->end() |
||
| 137 | ->info('URLs of the Varnish servers to purge using cache tags when a resource is updated.') |
||
| 138 | ->end() |
||
| 139 | ->end() |
||
| 140 | ->end() |
||
| 141 | ->end() |
||
| 142 | ->end() |
||
| 143 | |||
| 144 | ->end(); |
||
| 145 | |||
| 146 | $this->addExceptionToStatusSection($rootNode); |
||
| 147 | |||
| 148 | $this->addFormatSection($rootNode, 'formats', [ |
||
| 149 | 'jsonld' => ['mime_types' => ['application/ld+json']], |
||
| 150 | 'json' => ['mime_types' => ['application/json']], // Swagger support |
||
| 151 | 'html' => ['mime_types' => ['text/html']], // Swagger UI support |
||
| 152 | ]); |
||
| 153 | $this->addFormatSection($rootNode, 'error_formats', [ |
||
| 154 | 'jsonproblem' => ['mime_types' => ['application/problem+json']], |
||
| 155 | 'jsonld' => ['mime_types' => ['application/ld+json']], |
||
| 156 | ]); |
||
| 157 | |||
| 158 | return $treeBuilder; |
||
| 159 | } |
||
| 160 | |||
| 252 |