| Conditions | 6 |
| Paths | 15 |
| Total Lines | 66 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 2 |
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 |
||
| 45 | public function execute(Request $request, $params=[]) |
||
| 46 | { |
||
| 47 | $connection = $this->getConnection(); |
||
| 48 | |||
| 49 | $url = $this->_connection->getConfig('scheme') . '://' . $connection->getHost() . ':' . $connection->getPort(); |
||
| 50 | $endpoint = $request->getPath(); |
||
| 51 | $url .= $endpoint; |
||
| 52 | $url = $this->setupURI($url, $request->getQuery()); |
||
| 53 | $method = $request->getMethod(); |
||
| 54 | |||
| 55 | $headers = $connection->getHeaders(); |
||
| 56 | $headers['Content-Type'] = $request->getContentType(); |
||
| 57 | $data = $request->getBody(); |
||
| 58 | if (!empty($data)) { |
||
| 59 | if (is_array($data)) { |
||
| 60 | $content = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES); |
||
| 61 | } else { |
||
| 62 | $content = $data; |
||
| 63 | } |
||
| 64 | } else { |
||
| 65 | $content = ''; |
||
| 66 | } |
||
| 67 | $start = microtime(true); |
||
| 68 | $message = $this->messageFactory->createRequest($method, $url, $headers, $content); |
||
| 69 | try { |
||
| 70 | $responsePSR = $this->client->sendRequest($message); |
||
| 71 | } catch (\Exception $e) { |
||
| 72 | throw new ConnectionException($e->getMessage(), $request); |
||
| 73 | } |
||
| 74 | $end = microtime(true); |
||
| 75 | $status = $responsePSR->getStatusCode(); |
||
| 76 | $responseString = $responsePSR->getBody(); |
||
| 77 | |||
| 78 | if (isset($params['responseClass'])) { |
||
| 79 | $responseClass = $params['responseClass']; |
||
| 80 | $response = new $responseClass($responseString, $status); |
||
| 81 | } else { |
||
| 82 | $response = new Response($responseString, $status); |
||
| 83 | } |
||
| 84 | |||
| 85 | $time = $end-$start; |
||
| 86 | $response->setTime($time); |
||
| 87 | $response->setTransportInfo([ |
||
| 88 | 'url' => $url, |
||
| 89 | 'headers' => $headers, |
||
| 90 | 'body' => $request->getBody() |
||
| 91 | ]); |
||
| 92 | $this->_logger->debug('Request body:', [ |
||
| 93 | 'connection' => $connection->getConfig(), |
||
| 94 | 'payload'=> $request->getBody() |
||
| 95 | ]); |
||
| 96 | $this->_logger->info( |
||
| 97 | 'Request:', |
||
| 98 | [ |
||
| 99 | 'url' => $url, |
||
| 100 | 'status' => $status, |
||
| 101 | 'time' => $time |
||
| 102 | ] |
||
| 103 | ); |
||
| 104 | $this->_logger->debug('Response body:', $response->getResponse()); |
||
| 105 | |||
| 106 | if ($response->hasError()) { |
||
| 107 | $this->_logger->error('Response error:', [$response->getError()]); |
||
| 108 | throw new ResponseException($request, $response); |
||
| 109 | } |
||
| 110 | return $response; |
||
| 111 | } |
||
| 113 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths