| Conditions | 10 |
| Paths | 144 |
| Total Lines | 39 |
| Code Lines | 30 |
| 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 |
||
| 48 | public function import(): void |
||
| 49 | { |
||
| 50 | if ($this->config->get('log_all')) { |
||
| 51 | $this->controller->log('Start import ' . $this->name, []); |
||
| 52 | } |
||
| 53 | $fieldName = $this->fieldModel->getName(); |
||
| 54 | $picklistValues = \App\Fields\Picklist::getValues($fieldName); |
||
| 55 | $values = []; |
||
| 56 | foreach ($picklistValues as $value) { |
||
| 57 | $values[mb_strtolower($value['picklistValue'])] = $value['picklistValue']; |
||
| 58 | $values[mb_strtolower(\App\Language::translate($value['picklistValue'], 'Accounts'))] = $value['picklistValue']; |
||
| 59 | } |
||
| 60 | if (\in_array('Przelew', array_column($this->cache, 'kon_Wartosc')) && isset($values['pll_transfer'])) { |
||
| 61 | $values['przelew'] = $values['pll_transfer']; |
||
| 62 | } |
||
| 63 | $i = 0; |
||
| 64 | foreach ($this->cache as $value) { |
||
| 65 | if (empty($value['kon_Wartosc'])) { |
||
| 66 | continue; |
||
| 67 | } |
||
| 68 | $name = mb_strtolower($value['kon_Wartosc']); |
||
| 69 | if (empty($values[$name])) { |
||
| 70 | try { |
||
| 71 | $itemModel = $this->fieldModel->getItemModel(); |
||
| 72 | $itemModel->validateValue('name', $value['kon_Wartosc']); |
||
| 73 | $itemModel->set('name', $value['kon_Wartosc']); |
||
| 74 | $itemModel->save(); |
||
| 75 | $this->cacheList[$value['kon_Wartosc']] = $value['kon_Lp']; |
||
| 76 | ++$i; |
||
| 77 | } catch (\Throwable $ex) { |
||
| 78 | $this->controller->log('Import ' . $this->name, ['API' => $value], $ex); |
||
| 79 | \App\Log::error("Error during import {$this->name}: \n{$ex->__toString()}", self::LOG_CATEGORY); |
||
| 80 | } |
||
| 81 | } else { |
||
| 82 | $this->cacheList[$values[$name]] = $value['kon_Lp']; |
||
| 83 | } |
||
| 84 | } |
||
| 85 | if ($this->config->get('log_all')) { |
||
| 86 | $this->controller->log('End import ' . $this->name, ['imported' => $i]); |
||
| 87 | } |
||
| 142 |