| Conditions | 5 |
| Paths | 9 |
| Total Lines | 69 |
| Code Lines | 32 |
| 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 |
||
| 43 | public function handle() |
||
| 44 | { |
||
| 45 | $cityId = $this->argument('city'); |
||
| 46 | |||
| 47 | $url = $this->argument('url'); |
||
| 48 | |||
| 49 | $limit = (int)$this->option('limit'); |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Получаем список всех страниц с улицами |
||
| 53 | */ |
||
| 54 | $firstPage = $this->download($url); |
||
| 55 | |||
| 56 | $allPages = (int)(new Crawler($firstPage))->filter('.uk-pagination > li')->last()->text(); |
||
| 57 | |||
| 58 | $k = 0; |
||
| 59 | for ($i = 1; $i <= $allPages; $i++) { |
||
| 60 | /** |
||
| 61 | * Получам список улиц на текущей странице |
||
| 62 | */ |
||
| 63 | $page = $this->download($url . '/page-' . $i . '/'); |
||
| 64 | |||
| 65 | $this->line('Downloading streets and building numbers from page #' . $i . ' from ' . $allPages); |
||
| 66 | |||
| 67 | $streets = (new Crawler($page))->filter('.c4 > a'); |
||
| 68 | |||
| 69 | $streets->each(function ($node) { |
||
| 70 | /** |
||
| 71 | * Получаем список домов |
||
| 72 | */ |
||
| 73 | $url = 'http://www.city-address.ru' . $node->attr('href'); |
||
| 74 | |||
| 75 | $page = $this->download($url); |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Обрабатываем список домов |
||
| 79 | */ |
||
| 80 | $numbers = collect((new Crawler($page))->filter('.c6 > div > a')->extract('_text')) |
||
| 81 | ->reject(function ($item, $key) { |
||
| 82 | return strpos($item, 'дом ') !== 0; |
||
| 83 | })->map(function ($item, $key) { |
||
| 84 | return str_replace('дом № ', '', $item); |
||
| 85 | })->toArray(); |
||
| 86 | |||
| 87 | $this->streets->put($node->text(), $numbers); |
||
| 88 | }); |
||
| 89 | |||
| 90 | if (++$k == $limit) { |
||
| 91 | $this->warn('Interrupted by the limit'); |
||
| 92 | break; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Генерируем контент для файла с данными |
||
| 98 | */ |
||
| 99 | $output = '<?php' . PHP_EOL . PHP_EOL; |
||
| 100 | $output .= 'return [' . PHP_EOL; |
||
| 101 | foreach ($this->streets as $street => $numbers) { |
||
| 102 | $glueNumbers = implode('", "', $numbers); |
||
| 103 | if (!empty($glueNumbers)) { |
||
| 104 | $output .= ' "' . trim($street, ";") . '" => ["' . $glueNumbers . '"],' . PHP_EOL; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | $output .= '];' . PHP_EOL; |
||
| 108 | |||
| 109 | Storage::put($cityId . '.php', $output); |
||
| 110 | |||
| 111 | $this->info('Data was saved'); |
||
| 112 | } |
||
| 121 |
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