| Conditions | 9 |
| Paths | 20 |
| Total Lines | 38 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 23 |
| CRAP Score | 9.0414 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 28 | 1 | public function handle() |
|
| 29 | { |
||
| 30 | 1 | $start = (int) $this->argument('start'); |
|
| 31 | 1 | if ($start <= 0) { |
|
| 32 | 1 | $modelClass = MyriadDataDownloader::$contactModel; |
|
| 33 | 1 | $start = $modelClass::select(['id'])->orderBy('id', 'DESC')->first()?->id ?: 0; |
|
| 34 | 1 | $start += 1; |
|
| 35 | } |
||
| 36 | 1 | $buffer = (int) $this->option('buffer'); |
|
| 37 | 1 | if ($buffer < 0 || $buffer > 500) { |
|
| 38 | $this->error("Invalid buffer value [$buffer]"); |
||
| 39 | |||
| 40 | return 1; |
||
| 41 | } |
||
| 42 | |||
| 43 | 1 | $successDownloads = 0; |
|
| 44 | 1 | $errors = 0; |
|
| 45 | 1 | for ($i = $start; $i <= ($start + 1000); $i++) { |
|
| 46 | try { |
||
| 47 | 1 | $myriadContact = (new \MyriadDataStore\Actions\DownloadMyriadContact()) |
|
| 48 | 1 | ->execute($i); |
|
| 49 | 1 | if ($myriadContact) { |
|
| 50 | 1 | $successDownloads++; |
|
| 51 | 1 | (new \MyriadDataStore\Actions\DownloadMyriadContactOrdersBasic()) |
|
| 52 | 1 | ->execute($i); |
|
| 53 | } |
||
| 54 | 1 | } catch (MyriadSoapException $e) { |
|
| 55 | 1 | $errors++; |
|
| 56 | } |
||
| 57 | |||
| 58 | 1 | if ($errors >= $buffer) { |
|
| 59 | 1 | break; |
|
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 63 | 1 | $this->info("Successful downloaded: {$successDownloads} contacts."); |
|
| 64 | |||
| 65 | 1 | return 0; |
|
| 66 | } |
||
| 68 |