Conditions | 6 |
Paths | 5 |
Total Lines | 69 |
Code Lines | 51 |
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 |
||
226 | private function createDefaultProxyFactory(): ProxyFactory |
||
227 | { |
||
228 | if ($this->baseUrl === null) { |
||
229 | throw new LogicException('Retrofit: Base URL must be provided'); |
||
230 | } |
||
231 | |||
232 | if ($this->httpClient === null) { |
||
233 | throw new LogicException('Retrofit: Must set http client to make requests'); |
||
234 | } |
||
235 | |||
236 | if ($this->shouldCache && $this->cacheDir === null) { |
||
237 | throw new LogicException('Retrofit: If caching is enabled, must specify cache directory'); |
||
238 | } |
||
239 | |||
240 | $this->cacheDir .= '/retrofit'; |
||
241 | |||
242 | // add defaults to any user registered |
||
243 | $this->callAdapterFactories[] = new DefaultCallAdapterFactory(); |
||
244 | $this->converterFactories[] = new DefaultConverterFactory(); |
||
245 | |||
246 | $cache = $this->shouldCache |
||
247 | ? new ChainCache([new ArrayCache(), new FilesystemCache()]) |
||
248 | : new ArrayCache(); |
||
249 | |||
250 | $httpRequestHandler = new AnnotHandler\HttpRequestAnnotHandler(); |
||
251 | $annotationHandlers = array_merge( |
||
252 | [ |
||
253 | Annot\Body::class => new AnnotHandler\BodyAnnotHandler(), |
||
254 | Annot\DELETE::class => $httpRequestHandler, |
||
255 | Annot\Field::class => new AnnotHandler\FieldAnnotHandler(), |
||
256 | Annot\FieldMap::class => new AnnotHandler\FieldMapAnnotHandler(), |
||
257 | Annot\GET::class => $httpRequestHandler, |
||
258 | Annot\HEAD::class => $httpRequestHandler, |
||
259 | Annot\Header::class => new AnnotHandler\HeaderAnnotHandler(), |
||
260 | Annot\HeaderMap::class => new AnnotHandler\HeaderMapAnnotHandler(), |
||
261 | Annot\Headers::class => new AnnotHandler\HeadersAnnotHandler(), |
||
262 | Annot\OPTIONS::class => $httpRequestHandler, |
||
263 | Annot\Part::class => new AnnotHandler\PartAnnotHandler(), |
||
264 | Annot\PartMap::class => new AnnotHandler\PartMapAnnotHandler(), |
||
265 | Annot\PATCH::class => $httpRequestHandler, |
||
266 | Annot\Path::class => new AnnotHandler\PathAnnotHandler(), |
||
267 | Annot\POST::class => $httpRequestHandler, |
||
268 | Annot\PUT::class => $httpRequestHandler, |
||
269 | Annot\Query::class => new AnnotHandler\QueryAnnotHandler(), |
||
270 | Annot\QueryMap::class => new AnnotHandler\QueryMapAnnotHandler(), |
||
271 | Annot\QueryName::class => new AnnotHandler\QueryNameAnnotHandler(), |
||
272 | Annot\REQUEST::class => $httpRequestHandler, |
||
273 | Annot\Url::class => new AnnotHandler\UrlAnnotHandler(), |
||
274 | ], |
||
275 | $this->annotationHandlers |
||
276 | ); |
||
277 | $serviceMethodFactory = new ServiceMethodFactory( |
||
278 | new AnnotationProcessor($annotationHandlers), |
||
279 | new CallAdapterProvider($this->callAdapterFactories), |
||
280 | new ConverterProvider($this->converterFactories), |
||
281 | new AnnotationReaderAdapter(new AnnotationReader(), $cache), |
||
282 | $this->baseUrl |
||
283 | ); |
||
284 | |||
285 | return new DefaultProxyFactory( |
||
286 | new BuilderFactory(), |
||
287 | new Standard(), |
||
288 | $serviceMethodFactory, |
||
289 | $this->httpClient, |
||
290 | new Filesystem(), |
||
291 | $this->shouldCache, |
||
292 | $this->cacheDir |
||
293 | ); |
||
294 | } |
||
295 | } |
||
296 |