| Conditions | 10 |
| Paths | 11 |
| Total Lines | 30 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 28 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
| 29 | { |
||
| 30 | $response = $handler->handle($request); |
||
| 31 | $stream = $response->getBody(); |
||
| 32 | if (!$stream instanceof BucketStream || $stream->hasConverter()) { |
||
| 33 | return $response; |
||
| 34 | } |
||
| 35 | |||
| 36 | $bucket = $stream->getBucket(); |
||
| 37 | |||
| 38 | // Bucket has been detached |
||
| 39 | if ($bucket === null) { |
||
| 40 | return $stream->isReadable() ? $response : $response->withBody($this->streamFactory->createStream('')); |
||
| 41 | } |
||
| 42 | |||
| 43 | if (!$bucket->isFormatable() && !$stream->isReadable()) { |
||
| 44 | $response = $response->withBody($this->createReadableStream($bucket->getData())); |
||
| 45 | } |
||
| 46 | |||
| 47 | // Set MIME type |
||
| 48 | $matching = $stream->getMatchedResult(); |
||
|
|
|||
| 49 | if ($matching !== null && $matching->getMimeType() !== null) { |
||
| 50 | $response = $response->withHeader(Header::CONTENT_TYPE, $matching->getMimeType()); |
||
| 51 | } |
||
| 52 | |||
| 53 | // Update request |
||
| 54 | if ($bucket->getCode() !== null) { |
||
| 55 | $response = $response->withStatus($bucket->getCode()); |
||
| 56 | } |
||
| 57 | return $this->addHeaders($response, $bucket->getHeaders()); |
||
| 58 | } |
||
| 78 |
This check looks for function or method calls that always return null and whose return value is assigned to a variable.
The method
getObject()can return nothing but null, so it makes no sense to assign that value to a variable.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.