| Conditions | 14 |
| Paths | 64 |
| Total Lines | 65 |
| Code Lines | 46 |
| 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 |
||
| 51 | public function updateDb() { |
||
| 52 | // Обновление файла базы данных Sypex Geo |
||
| 53 | // Настройки |
||
| 54 | $url = 'https://sypexgeo.net/files/SxGeoCity_utf8.zip'; // Путь к скачиваемому файлу |
||
| 55 | $dat_file_dir = App::$primary->path . $this->geographyDbDir; // Каталог в который сохранять dat-файл |
||
| 56 | $last_updated_file = $dat_file_dir . '/SxGeo.upd'; // Файл в котором хранится дата последнего обновления |
||
| 57 | $info = false; // Вывод сообщений о работе, true заменить на false после установки в cron |
||
| 58 | |||
| 59 | // Конец настроек |
||
| 60 | |||
| 61 | set_time_limit(600); |
||
| 62 | //error_reporting(E_ALL); |
||
| 63 | //header('Content-type: text/plain; charset=utf8'); |
||
| 64 | |||
| 65 | $t = microtime(1); |
||
| 66 | Tools::createDir($dat_file_dir); |
||
| 67 | $types = array( |
||
| 68 | 'Country' => 'SxGeo.dat', |
||
| 69 | 'City' => 'SxGeoCity.dat', |
||
| 70 | 'Max' => 'SxGeoMax.dat', |
||
| 71 | ); |
||
| 72 | // Скачиваем архив |
||
| 73 | preg_match("/(Country|City|Max)/", pathinfo($url, PATHINFO_BASENAME), $m); |
||
| 74 | $type = $m[1]; |
||
| 75 | $dat_file = $types[$type]; |
||
| 76 | if ($info) echo "Скачиваем архив с сервера\n"; |
||
| 77 | |||
| 78 | $fp = fopen($dat_file_dir . '/SxGeoTmp.zip', 'wb'); |
||
| 79 | $ch = curl_init($url); |
||
| 80 | curl_setopt_array($ch, array( |
||
| 81 | CURLOPT_FILE => $fp, |
||
| 82 | CURLOPT_HTTPHEADER => file_exists($last_updated_file) ? array("If-Modified-Since: " . file_get_contents($last_updated_file)) : array(), |
||
| 83 | )); |
||
| 84 | if (!curl_exec($ch)) { |
||
| 85 | if ($info) echo 'Ошибка при скачивании архива'; |
||
| 86 | return; |
||
| 87 | } |
||
| 88 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
||
| 89 | curl_close($ch); |
||
| 90 | fclose($fp); |
||
| 91 | if ($code == 304) { |
||
| 92 | @unlink($dat_file_dir . '/SxGeoTmp.zip'); |
||
| 93 | if ($info) echo "Архив не обновился, с момента предыдущего скачивания\n"; |
||
| 94 | return; |
||
| 95 | } |
||
| 96 | |||
| 97 | if ($info) echo "Архив с сервера скачан\n"; |
||
| 98 | // Распаковываем архив |
||
| 99 | $fp = fopen('zip://' . $dat_file_dir . '/SxGeoTmp.zip#' . $dat_file, 'rb'); |
||
| 100 | $fw = fopen($dat_file_dir . '/' . $dat_file, 'wb'); |
||
| 101 | if (!$fp) { |
||
| 102 | if ($info) |
||
| 103 | echo "Не получается открыть\n"; |
||
| 104 | return; |
||
| 105 | } |
||
| 106 | if ($info) echo "Распаковываем архив\n"; |
||
| 107 | stream_copy_to_stream($fp, $fw); |
||
| 108 | fclose($fp); |
||
| 109 | fclose($fw); |
||
| 110 | if (filesize($dat_file) == 0) { |
||
| 111 | if ($info) echo 'Ошибка при распаковке архива'; |
||
| 112 | } |
||
| 113 | @unlink($dat_file_dir . '/SxGeoTmp.zip'); |
||
| 114 | file_put_contents($last_updated_file, gmdate('D, d M Y H:i:s') . ' GMT'); |
||
| 115 | if ($info) echo "Перемещен файл в {$dat_file_dir}/{$dat_file}\n"; |
||
| 116 | |||
| 120 |
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