Conditions | 12 |
Paths | 36 |
Total Lines | 70 |
Code Lines | 44 |
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 |
||
49 | protected function process(Request $request) |
||
50 | { |
||
51 | $headers = []; |
||
52 | foreach ($request->getHeaders() as $name => $value) { |
||
53 | $headers[] = "$name: $value"; |
||
54 | } |
||
55 | |||
56 | $responseHeaders = []; |
||
57 | $softOptions = [ |
||
58 | CURLOPT_CONNECTTIMEOUT => 10, |
||
59 | CURLOPT_SSL_VERIFYHOST => 2, |
||
60 | CURLOPT_SSL_VERIFYPEER => 1, |
||
61 | CURLOPT_CAINFO => realpath(__DIR__ . '/../ca-chain.crt'), |
||
62 | ]; |
||
63 | |||
64 | $hardOptions = [ |
||
65 | CURLOPT_FOLLOWLOCATION => FALSE, # Github sets the Location header for 201 code too and redirection is not required for us |
||
66 | CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, |
||
67 | CURLOPT_CUSTOMREQUEST => $request->getMethod(), |
||
68 | CURLOPT_NOBODY => $request->isMethod(Request::HEAD), |
||
69 | CURLOPT_URL => $request->getUrl(), |
||
70 | CURLOPT_HTTPHEADER => $headers, |
||
71 | CURLOPT_RETURNTRANSFER => TRUE, |
||
72 | CURLOPT_POSTFIELDS => $request->getContent(), |
||
73 | CURLOPT_HEADER => FALSE, |
||
74 | CURLOPT_HEADERFUNCTION => function($curl, $line) use (& $responseHeaders, & $last) { |
||
75 | if (strncasecmp($line, 'HTTP/', 5) === 0) { |
||
76 | /** @todo Set proxy response as Response::setPrevious($proxyResponse)? */ |
||
77 | # The HTTP/x.y may occur multiple times with proxy (HTTP/1.1 200 Connection Established) |
||
78 | $responseHeaders = []; |
||
79 | |||
80 | } elseif (in_array(substr($line, 0, 1), [' ', "\t"], TRUE)) { |
||
81 | $responseHeaders[$last] .= ' ' . trim($line); # RFC2616, 2.2 |
||
82 | |||
83 | } elseif ($line !== "\r\n") { |
||
84 | list($name, $value) = explode(':', $line, 2); |
||
85 | $responseHeaders[$last = trim($name)] = trim($value); |
||
86 | } |
||
87 | |||
88 | return strlen($line); |
||
89 | }, |
||
90 | ]; |
||
91 | |||
92 | if (defined('CURLOPT_PROTOCOLS')) { # HHVM issue. Even cURL v7.26.0, constants are missing. |
||
93 | $hardOptions[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS; |
||
94 | } |
||
95 | |||
96 | if (!$this->curl) { |
||
97 | $this->curl = curl_init(); |
||
98 | if ($this->curl === FALSE) { |
||
99 | throw new BadResponseException('Cannot init cURL handler.'); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | $result = curl_setopt_array($this->curl, $hardOptions + ($this->options ?: []) + $softOptions); |
||
104 | if ($result === FALSE) { |
||
105 | throw new BadResponseException('Setting cURL options failed: ' . curl_error($this->curl), curl_errno($this->curl)); |
||
106 | } |
||
107 | |||
108 | $content = curl_exec($this->curl); |
||
109 | if ($content === FALSE) { |
||
110 | throw new BadResponseException(curl_error($this->curl), curl_errno($this->curl)); |
||
111 | } |
||
112 | |||
113 | $code = curl_getinfo($this->curl, CURLINFO_HTTP_CODE); |
||
114 | if ($code === FALSE) { |
||
115 | throw new BadResponseException('HTTP status code is missing:' . curl_error($this->curl), curl_errno($this->curl)); |
||
116 | } |
||
117 | |||
118 | return new Response($code, $responseHeaders, $content); |
||
119 | } |
||
122 |
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