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