| Conditions | 5 |
| Paths | 12 |
| Total Lines | 55 |
| 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 |
||
| 133 | protected function fetchCertificates(string $hostName): array |
||
| 134 | { |
||
| 135 | $hostName = (new Url($hostName))->getHostName(); |
||
| 136 | |||
| 137 | $sslOptions = [ |
||
| 138 | 'capture_peer_cert' => true, |
||
| 139 | 'capture_peer_cert_chain' => $this->capturePeerChain, |
||
| 140 | 'SNI_enabled' => $this->enableSni, |
||
| 141 | 'peer_name' => $hostName, |
||
| 142 | 'verify_peer' => $this->verifyPeer, |
||
| 143 | 'verify_peer_name' => $this->verifyPeerName, |
||
| 144 | ]; |
||
| 145 | |||
| 146 | $streamContext = stream_context_create([ |
||
| 147 | 'ssl' => $sslOptions, |
||
| 148 | ]); |
||
| 149 | |||
| 150 | if ($this->usingIpAddress) { |
||
| 151 | $connectTo = $this->ipAddress; |
||
| 152 | } else { |
||
| 153 | $connectTo = $hostName; |
||
| 154 | } |
||
| 155 | |||
| 156 | try { |
||
| 157 | $client = stream_socket_client( |
||
| 158 | "ssl://{$connectTo}:{$this->port}", |
||
| 159 | $errorNumber, |
||
| 160 | $errorDescription, |
||
| 161 | $this->timeout, |
||
| 162 | STREAM_CLIENT_CONNECT, |
||
| 163 | $streamContext |
||
| 164 | ); |
||
| 165 | } catch (Throwable $thrown) { |
||
| 166 | $this->handleRequestFailure($connectTo, $thrown); |
||
| 167 | } |
||
| 168 | |||
| 169 | if (! $client) { |
||
| 170 | if ($this->usingIpAddress) { |
||
| 171 | throw CouldNotDownloadCertificate::unknownError( |
||
| 172 | $hostName, |
||
| 173 | "Could not connect to `{$connectTo}` or it does not have a certificate matching `${hostName}`." |
||
| 174 | ); |
||
| 175 | } else { |
||
| 176 | throw CouldNotDownloadCertificate::unknownError($hostName, "Could not connect to `{$connectTo}`."); |
||
| 177 | } |
||
| 178 | } |
||
| 179 | |||
| 180 | $response = stream_context_get_params($client); |
||
| 181 | |||
| 182 | $response['remoteAddress'] = stream_socket_get_name($client, true); |
||
| 183 | |||
| 184 | fclose($client); |
||
| 185 | |||
| 186 | return $response; |
||
| 187 | } |
||
| 188 | |||
| 202 |