| Conditions | 7 |
| Paths | 13 |
| Total Lines | 54 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 | private function handleDepartments($departments) |
||
| 52 | { |
||
| 53 | foreach($departments as $department){ |
||
| 54 | $key = key($department); |
||
| 55 | $department = last($department)['printouts']; |
||
| 56 | |||
| 57 | $climat = last($department['A un climat'])['fulltext']; |
||
| 58 | $number = last($department['A un numéro de département']); |
||
| 59 | $name = last($department['A un nom']); |
||
| 60 | $iconUrlApi = str_replace(':file:', last($department['A une icone'])['fulltext'], $this->queryPictures); |
||
| 61 | |||
| 62 | $characteristicModel = CharacteristicsModel::query()->where('code', $number)->first(); |
||
| 63 | if(!isset($characteristicModel)){ |
||
| 64 | $characteristicModel = new CharacteristicsModel(); |
||
| 65 | } |
||
| 66 | |||
| 67 | $characteristicModel->uuid = $uuid = Uuid::uuid4(); |
||
| 68 | $characteristicModel->priority = 10000; |
||
| 69 | $characteristicModel->page_label = $key; |
||
| 70 | $characteristicModel->pretty_page_label = $name; |
||
| 71 | $characteristicModel->type = Characteristic::DEPARTMENT; |
||
| 72 | $characteristicModel->code = $number; |
||
| 73 | $characteristicModel->opt = [ |
||
| 74 | 'number' => $number, |
||
| 75 | 'climat' => $climat, |
||
| 76 | 'url' => 'wiki/'.str_replace(' ', '_', $climat) |
||
| 77 | ]; |
||
| 78 | |||
| 79 | |||
| 80 | $response = $this->httpClient->get(config('wiki.api_uri').$iconUrlApi); |
||
| 81 | $content = json_decode($response->getBody()->getContents(), true); |
||
| 82 | $picturesInfo = $content['query']['pages']; |
||
| 83 | foreach($picturesInfo as $picture) { |
||
| 84 | if (isset($picture['imageinfo']) && isset(last($picture['imageinfo'])['url'])) { |
||
| 85 | $characteristicModel->page_id = $picture['pageid']; |
||
| 86 | try { |
||
| 87 | $response = $this->httpClient->get(last($picture['imageinfo'])['url']); |
||
| 88 | $content = $response->getBody()->getContents(); |
||
| 89 | $path = 'public/characteristics/' . $uuid . '.png'; |
||
| 90 | Storage::put('public/characteristics/' . $uuid . '.png', $content); |
||
| 91 | }catch (ClientException $e){ |
||
| 92 | $this->info('No icon for department : '.$number); |
||
| 93 | $path = ''; |
||
| 94 | } |
||
| 95 | }else{ |
||
| 96 | $this->info('No icon for department : '.$number); |
||
| 97 | $path = ''; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | $characteristicModel->icon = $path; |
||
|
|
|||
| 102 | $characteristicModel->visible = false; |
||
| 103 | |||
| 104 | $characteristicModel->save(); |
||
| 105 | } |
||
| 108 |