DownloadMyriadOrdersBasicForContacts   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 32
ccs 5
cts 15
cp 0.3333
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 10 5
A __construct() 0 11 4
1
<?php
2
3
namespace MyriadDataStore\Jobs;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Contracts\Queue\ShouldQueue;
7
use Illuminate\Foundation\Bus\Dispatchable;
8
use Illuminate\Queue\InteractsWithQueue;
9
use Illuminate\Queue\SerializesModels;
10
use Illuminate\Support\Facades\Log;
11
use MyriadSoap\MyriadSoapException;
12
13
class DownloadMyriadOrdersBasicForContacts implements ShouldQueue
14
{
15
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by MyriadDataStore\Jobs\Dow...dOrdersBasicForContacts: $collectionClass, $id, $relations, $class, $keyBy
Loading history...
16
17
    public static bool|string $logErrors = false;
18
19
    protected int $startContactId = 1;
20
    protected int $count          = 1000;
21
22 1
    public function __construct($startContactId = 1, $count = 1000)
23
    {
24 1
        if ($startContactId <= 0) {
25
            throw new \Exception("Invalid start value [$startContactId]");
26
        }
27 1
        if ($count <= 0 || $count > 100000) {
28
            throw new \Exception("Invalid count value [$count]");
29
        }
30
31 1
        $this->startContactId = $startContactId;
32 1
        $this->count          = $count;
33
    }
34
35
    public function handle(\MyriadDataStore\Actions\DownloadMyriadContactOrdersBasic $action)
36
    {
37
        for ($i = $this->startContactId; $i < ($this->startContactId + $this->count); $i++) {
38
            try {
39
                $action->execute($i);
40
            } catch (MyriadSoapException $e) {
41
                if (static::$logErrors) {
42
                    Log::log(
43
                        is_string(static::$logErrors) ? static::$logErrors : 'error',
44
                        "Contact [$i] orders download error: ".$e->getMessage()
45
                    );
46
                }
47
            }
48
        }
49
    }
50
}
51