DownloadMyriadOrdersBasicForContacts   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 35
c 1
b 0
f 0
dl 0
loc 67
ccs 29
cts 29
cp 1
rs 10
wmc 9

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 47 9
1
<?php
2
3
namespace MyriadDataStore\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use MyriadSoap\MyriadSoapException;
7
8
class DownloadMyriadOrdersBasicForContacts extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'myriad-download:contacts-orders-basic
16
    {start=1 : Start contact ID}
17
    {--count=1000 : Count identifiers}
18
    {--queue=sync : Queue name}
19
    ';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Download/Update myriad orders for contacts batch';
27
28 4
    public function handle()
29
    {
30 4
        $start = (int) $this->argument('start');
31 4
        if ($start <= 0) {
32 1
            $this->error("Invalid start value [$start]");
33
34 1
            return 1;
35
        }
36 4
        $count = (int) $this->option('count');
37 4
        if ($count <= 0 || $count > 100000) {
38 1
            $this->error("Invalid count value [$count]");
39
40 1
            return 1;
41
        }
42 3
        $queue = (string) $this->option('queue');
43
44 3
        if ($queue === 'sync') {
45 2
            $successDownloads = 0;
46 2
            $errorDownloads   = 0;
47
48 2
            for ($i = $start; $i < ($start + $count); $i++) {
49
                try {
50 2
                    $myriadContact = (new \MyriadDataStore\Actions\DownloadMyriadContactOrdersBasic())
51 2
                        ->execute($i);
52 1
                    if ($myriadContact) {
53 1
                        $successDownloads++;
54
                    } else {
55 1
                        $errorDownloads++;
56
                    }
57 1
                } catch (MyriadSoapException $e) {
58 1
                    $this->error("Contact [$i] error: ".$e->getMessage());
59 1
                    $errorDownloads++;
60
                }
61
            }
62
63 2
            if ($errorDownloads == 0) {
0 ignored issues
show
introduced by
The condition $errorDownloads == 0 is always true.
Loading history...
64 1
                $this->info("Successful downloaded orders for {$successDownloads} contacts.");
65
            } else {
66 1
                $this->warn("Successful downloaded orders for {$successDownloads} contacts.");
67 2
                $this->warn("Fails downloaded orders for {$errorDownloads} contacts.");
68
            }
69
        } else {
70 1
            \MyriadDataStore\Jobs\DownloadMyriadOrdersBasicForContacts::dispatch($start, $count)->onQueue($queue);
71 1
            $this->info("Job sent to queue [$queue].");
72
        }
73
74 3
        return 0;
75
    }
76
}
77