Conditions | 7 |
Paths | 10 |
Total Lines | 51 |
Code Lines | 35 |
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 |
||
90 | private function getContext(Request $request, Documentation $documentation): array |
||
91 | { |
||
92 | $context = [ |
||
93 | 'title' => $this->title, |
||
94 | 'description' => $this->description, |
||
95 | 'formats' => $this->formats, |
||
96 | ]; |
||
97 | |||
98 | $swaggerData = [ |
||
99 | 'url' => $this->urlGenerator->generate('api_doc', ['format' => 'json']), |
||
100 | 'spec' => $this->normalizer->normalize($documentation, 'json', ['base_url' => $request->getBaseUrl()]), |
||
101 | ]; |
||
102 | |||
103 | if (!$this->oauthRedirectUrl) { |
||
104 | $this->oauthRedirectUrl = $request->getScheme() . '://' . |
||
105 | $request->getHttpHost() . |
||
106 | $request->getBasePath() . |
||
107 | $this->assetPackages->getUrl('bundles/apiplatform/swagger-ui/oauth2-redirect.html'); |
||
108 | } |
||
109 | |||
110 | $swaggerData['oauth'] = [ |
||
111 | 'enabled' => $this->oauthEnabled, |
||
112 | 'clientId' => $this->oauthClientId, |
||
113 | 'clientSecret' => $this->oauthClientSecret, |
||
114 | 'type' => $this->oauthType, |
||
115 | 'flow' => $this->oauthFlow, |
||
116 | 'tokenUrl' => $this->oauthTokenUrl, |
||
117 | 'authorizationUrl' => $this->oauthAuthorizationUrl, |
||
118 | 'redirectUrl' => $this->oauthRedirectUrl, |
||
119 | 'scopes' => $this->oauthScopes, |
||
120 | ]; |
||
121 | |||
122 | if ($request->isMethodSafe(false) && null !== $resourceClass = $request->attributes->get('_api_resource_class')) { |
||
123 | $swaggerData['id'] = $request->attributes->get('id'); |
||
124 | $swaggerData['queryParameters'] = $request->query->all(); |
||
125 | |||
126 | $metadata = $this->resourceMetadataFactory->create($resourceClass); |
||
127 | $swaggerData['shortName'] = $metadata->getShortName(); |
||
128 | |||
129 | if (null !== $collectionOperationName = $request->attributes->get('_api_collection_operation_name')) { |
||
130 | $swaggerData['operationId'] = sprintf('%s%sCollection', $collectionOperationName, $swaggerData['shortName']); |
||
131 | } elseif (null !== $itemOperationName = $request->attributes->get('_api_item_operation_name')) { |
||
132 | $swaggerData['operationId'] = sprintf('%s%sItem', $itemOperationName, $swaggerData['shortName']); |
||
133 | } elseif (null !== $subresourceOperationContext = $request->attributes->get('_api_subresource_context')) { |
||
134 | $swaggerData['operationId'] = $subresourceOperationContext['operationId']; |
||
135 | } |
||
136 | |||
137 | list($swaggerData['path'], $swaggerData['method']) = $this->getPathAndMethod($swaggerData); |
||
138 | } |
||
139 | |||
140 | return $context + ['swagger_data' => $swaggerData]; |
||
141 | } |
||
156 |