Conditions | 9 |
Paths | 21 |
Total Lines | 63 |
Code Lines | 37 |
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 |
||
42 | public function collect(Request $request, Response $response, \Exception $exception = null) |
||
43 | { |
||
44 | $data = []; |
||
45 | |||
46 | foreach ($this->history as $request) { |
||
47 | /* @var \Psr\Http\Message\RequestInterface $request */ |
||
48 | $transaction = $this->history[$request]; |
||
49 | /* @var \Psr\Http\Message\ResponseInterface $response */ |
||
50 | $response = $transaction['response']; |
||
51 | /* @var \Exception $error */ |
||
52 | $error = $transaction['error']; |
||
53 | /* @var array $info */ |
||
54 | $info = $transaction['info']; |
||
55 | |||
56 | $req = [ |
||
57 | 'request' => [ |
||
58 | 'method' => $request->getMethod(), |
||
59 | 'version' => $request->getProtocolVersion(), |
||
60 | 'headers' => $request->getHeaders(), |
||
61 | 'body' => $this->cropContent($request->getBody()), |
||
62 | ], |
||
63 | 'info' => $info, |
||
64 | 'uri' => urldecode($request->getUri()), |
||
65 | 'httpCode' => 0, |
||
66 | 'error' => null, |
||
67 | ]; |
||
68 | |||
69 | if ($this->curlFormatter && $request->getBody()->getSize() <= $this->maxBodySize) { |
||
70 | $req['curl'] = $this->curlFormatter->format($request); |
||
71 | } |
||
72 | |||
73 | if ($response) { |
||
74 | $req['response'] = [ |
||
75 | 'reasonPhrase' => $response->getReasonPhrase(), |
||
76 | 'headers' => $response->getHeaders(), |
||
77 | 'body' => $this->cropContent($response->getBody()), |
||
78 | ]; |
||
79 | |||
80 | $req['httpCode'] = $response->getStatusCode(); |
||
81 | |||
82 | if ($response->hasHeader(CacheMiddleware::DEBUG_HEADER)) { |
||
83 | $req['cache'] = $response->getHeaderLine(CacheMiddleware::DEBUG_HEADER); |
||
84 | } |
||
85 | |||
86 | if ($response->hasHeader(MockMiddleware::DEBUG_HEADER)) { |
||
87 | $req['mock'] = $response->getHeaderLine(MockMiddleware::DEBUG_HEADER); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | if ($error && $error instanceof RequestException) { |
||
92 | $req['error'] = [ |
||
93 | 'message' => $error->getMessage(), |
||
94 | 'line' => $error->getLine(), |
||
95 | 'file' => $error->getFile(), |
||
96 | 'code' => $error->getCode(), |
||
97 | 'trace' => $error->getTraceAsString(), |
||
98 | ]; |
||
99 | } |
||
100 | |||
101 | $data[] = $req; |
||
102 | } |
||
103 | |||
104 | $this->data = $data; |
||
105 | } |
||
148 | } |