| Conditions | 17 |
| Paths | 12 |
| Total Lines | 75 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 31 | public function manageByHttpErrorMessage(string $errorMessage, string $url): string |
||
| 32 | { |
||
| 33 | // "410 gone" => {lien brisé} |
||
| 34 | if (preg_match('#410 Gone#i', $errorMessage)) { |
||
| 35 | $this->log->notice('410 Gone'); |
||
| 36 | |||
| 37 | if (ExternRefTransformer::REPLACE_410) { |
||
| 38 | return $this->deadLinkTransformer->formatFromUrl($url); |
||
| 39 | } |
||
| 40 | return $url; |
||
| 41 | } |
||
| 42 | if (preg_match('#400 Bad Request#i', $errorMessage)) { |
||
| 43 | $this->log->warning('400 Bad Request : ' . $url); |
||
| 44 | |||
| 45 | return $url; |
||
| 46 | } |
||
| 47 | if (preg_match('#(403 Forbidden|403 Access Forbidden)#i', $errorMessage)) { |
||
| 48 | $this->log->warning('403 Forbidden : ' . $url); |
||
| 49 | |||
| 50 | return $url; |
||
| 51 | } |
||
| 52 | if (preg_match('#404 Not Found#i', $errorMessage)) { |
||
| 53 | $this->log->notice('404 Not Found'); |
||
| 54 | |||
| 55 | if (ExternRefTransformer::REPLACE_404) { |
||
| 56 | return $this->deadLinkTransformer->formatFromUrl($url); |
||
| 57 | } |
||
| 58 | return $url; |
||
| 59 | } |
||
| 60 | if (preg_match('#401 (Unauthorized|Authorization Required)#i', $errorMessage)) { |
||
| 61 | $this->log->notice('401 Unauthorized : skip ' . $url); |
||
| 62 | |||
| 63 | return $url; |
||
| 64 | } |
||
| 65 | |||
| 66 | |||
| 67 | if (self::LOOSE && preg_match('#500 Internal Server Error#i', $errorMessage)) { |
||
| 68 | $this->log->notice('500 Internal Server Error'); |
||
| 69 | |||
| 70 | return $this->deadLinkTransformer->formatFromUrl($url); |
||
| 71 | } |
||
| 72 | if (self::LOOSE && preg_match('#502 Bad Gateway#i', $errorMessage)) { |
||
| 73 | $this->log->notice('502 Bad Gateway'); |
||
| 74 | |||
| 75 | return $this->deadLinkTransformer->formatFromUrl($url); |
||
| 76 | } |
||
| 77 | if (self::LOOSE && preg_match('#cURL error 52: Empty reply from server#i', $errorMessage)) { |
||
| 78 | $this->log->notice('cURL error 52: Empty reply from server'); |
||
| 79 | |||
| 80 | return $this->deadLinkTransformer->formatFromUrl($url); |
||
| 81 | } |
||
| 82 | |||
| 83 | // Faux-positif : cURL error 7: Failed to receive SOCKS5 connect request ack |
||
| 84 | if (self::LOOSE |
||
| 85 | && ( |
||
| 86 | preg_match("#cURL error 97: Can't complete SOCKS5 connection#i", $errorMessage) |
||
| 87 | || preg_match("#cURL error 7: Can't complete SOCKS5 connection to 0.0.0.0:0#i", $errorMessage) |
||
| 88 | ) |
||
| 89 | ) { |
||
| 90 | // remote endpoint connection failure |
||
| 91 | $this->log->notice("Can't complete SOCKS5 connection"); |
||
| 92 | |||
| 93 | return $this->deadLinkTransformer->formatFromUrl($url); |
||
| 94 | } |
||
| 95 | |||
| 96 | // DEFAULT (not filtered) |
||
| 97 | // autre : ne pas générer de {lien brisé}, car peut-être 404 temporaire |
||
| 98 | // "URL rejected: No host part in the URL (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) |
||
| 99 | // "cURL error 28: Connection timed out after 20005 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) |
||
| 100 | //"cURL error 28: Connection timed out after 20005 milliseconds (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) |
||
| 101 | $this->log->notice('erreur non gérée sur extractWebData: "' . $errorMessage . "\" URL: " . $url); |
||
| 102 | |||
| 103 | //file_put_contents(self::LOG_REQUEST_ERROR, $this->domain."\n", FILE_APPEND); |
||
| 104 | |||
| 105 | return $url; |
||
| 106 | } |
||
| 107 | } |