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