| Conditions | 9 | 
| Paths | 49 | 
| Total Lines | 54 | 
| Code Lines | 35 | 
| Lines | 15 | 
| Ratio | 27.78 % | 
| Changes | 2 | ||
| Bugs | 0 | Features | 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 | ||
| 29 | public function __invoke(HandlerContext $context) | ||
| 30 |     { | ||
| 31 | $callback = $context->annotations()->getCallback(); | ||
| 32 | |||
| 33 | View Code Duplication |         if ($callback !== null) { | |
| 34 |             if ($context->annotations()->isCallbackOptional()) { | ||
| 35 |                 $context->body()->add('if (%s !== null) {', $callback); | ||
| 36 |                 $context->body()->add('$returnEvent = new \Tebru\Retrofit\Event\ReturnEvent(null);'); | ||
| 37 |                 $context->body()->add('$this->eventDispatcher->dispatch("retrofit.return", $returnEvent);'); | ||
| 38 |                 $context->body()->add('return $returnEvent->getReturn();'); | ||
| 39 |                 $context->body()->add('}'); | ||
| 40 |             } else { | ||
| 41 |                 $context->body()->add('$returnEvent = new \Tebru\Retrofit\Event\ReturnEvent(null);'); | ||
| 42 |                 $context->body()->add('$this->eventDispatcher->dispatch("retrofit.return", $returnEvent);'); | ||
| 43 |                 $context->body()->add('return $returnEvent->getReturn();'); | ||
| 44 | |||
| 45 | return; | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | $returnType = 'array'; | ||
| 50 |         if (null !== $context->annotations()->getReturnType()) { | ||
| 51 | $returnType = $context->annotations()->getReturnType(); | ||
| 52 | } | ||
| 53 | |||
| 54 | $responseReturn = (null !== $context->annotations()->getResponseType()); | ||
| 55 |         if ($responseReturn) { | ||
| 56 | $returnType = $context->annotations()->getResponseType(); | ||
| 57 | } | ||
| 58 | |||
| 59 | $deserializationContext = (null !== $context->annotations()->getDeserializationContext()) | ||
| 60 | ? $context->annotations()->getDeserializationContext() | ||
| 61 | : []; | ||
| 62 | |||
| 63 |         if ('Response' === $returnType && false === $responseReturn) { | ||
| 64 |             throw new RetrofitException('A method return a Response must include a @ResponseType annotation.'); | ||
| 65 | } | ||
| 66 | |||
| 67 | $context->body()->add( | ||
| 68 | '$retrofitResponse = new \Tebru\Retrofit\Http\Response($response, "%s", $this->serializer, %s);', | ||
| 69 | $returnType, | ||
| 70 | $context->printer()->printArray($deserializationContext) | ||
| 71 | ); | ||
| 72 | |||
| 73 |         if ($responseReturn) { | ||
| 74 |             $context->body()->add('$return = $retrofitResponse;'); | ||
| 75 |         } else { | ||
| 76 |             $context->body()->add('$return = $retrofitResponse->body();'); | ||
| 77 | } | ||
| 78 | |||
| 79 |         $context->body()->add('$returnEvent = new \Tebru\Retrofit\Event\ReturnEvent($return);'); | ||
| 80 |         $context->body()->add('$this->eventDispatcher->dispatch("retrofit.return", $returnEvent);'); | ||
| 81 |         $context->body()->add('return $returnEvent->getReturn();'); | ||
| 82 | } | ||
| 83 | } | ||
| 84 |