| Conditions | 16 |
| Paths | 288 |
| Total Lines | 56 |
| Code Lines | 41 |
| 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 |
||
| 59 | public function import(): void |
||
| 60 | { |
||
| 61 | $this->lastScan = $this->config->getLastScan('import' . $this->name); |
||
| 62 | if ( |
||
| 63 | !$this->lastScan['start_date'] |
||
| 64 | || (0 === $this->lastScan['id'] && $this->lastScan['start_date'] === $this->lastScan['end_date']) |
||
| 65 | ) { |
||
| 66 | $this->config->setScan('import' . $this->name); |
||
| 67 | $this->lastScan = $this->config->getLastScan('import' . $this->name); |
||
| 68 | } |
||
| 69 | if ($this->config->get('log_all')) { |
||
| 70 | $this->controller->log('Start import ' . $this->name, [ |
||
| 71 | 'lastScan' => $this->lastScan, |
||
| 72 | ]); |
||
| 73 | } |
||
| 74 | $i = 0; |
||
| 75 | try { |
||
| 76 | $page = $this->lastScan['page'] ?? 1; |
||
| 77 | $load = true; |
||
| 78 | $finish = false; |
||
| 79 | $limit = $this->config->get(self::LIMIT_NAME); |
||
| 80 | while ($load) { |
||
| 81 | if ($rows = $this->getFromApi('Customer/GetAll?&page=' . $page . '&' . $this->getFromApiCond())) { |
||
| 82 | foreach ($rows as $id => $row) { |
||
| 83 | if ('JEDNORAZOWY' === $row['knt_Akronim']) { |
||
| 84 | continue; |
||
| 85 | } |
||
| 86 | $this->importItem($row); |
||
| 87 | $this->config->setScan('import' . $this->name, 'id', $id); |
||
| 88 | ++$i; |
||
| 89 | } |
||
| 90 | ++$page; |
||
| 91 | if (\is_callable($this->controller->bathCallback)) { |
||
| 92 | $load = \call_user_func($this->controller->bathCallback, 'import' . $this->name); |
||
| 93 | } |
||
| 94 | if ($limit !== \count($rows)) { |
||
| 95 | $finish = true; |
||
| 96 | } |
||
| 97 | } else { |
||
| 98 | $finish = true; |
||
| 99 | } |
||
| 100 | if ($finish || !$load) { |
||
| 101 | $load = false; |
||
| 102 | if ($finish) { |
||
| 103 | $this->config->setEndScan('import' . $this->name, $this->lastScan['start_date']); |
||
| 104 | } else { |
||
| 105 | $this->config->setScan('import' . $this->name, 'page', $page); |
||
| 106 | } |
||
| 107 | } |
||
| 108 | } |
||
| 109 | } catch (\Throwable $ex) { |
||
| 110 | $this->controller->log('Import ' . $this->name, null, $ex); |
||
| 111 | \App\Log::error("Error during import {$this->name}: \n{$ex->__toString()}", self::LOG_CATEGORY); |
||
| 112 | } |
||
| 113 | if ($this->config->get('log_all')) { |
||
| 114 | $this->controller->log('End import ' . $this->name, ['imported' => $i]); |
||
| 115 | } |
||
| 139 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.