AvailabilityPullCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 37
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 27 5
1
<?php
2
3
namespace IproSync\Console\Commands;
4
5
use Illuminate\Console\Command;
6
use IproSync\Jobs\Bookings\AvailabilityPull;
7
use IproSync\Models\Property;
8
9
class AvailabilityPullCommand extends Command
10
{
11
    protected $signature = 'iprosoftware-sync:availability:pull
12
     {--property_id= : Pull availability by ipro property id.}
13
     {--months=60 : the number of months of data to be returned, works only for day_availability.}
14
     {--queue= : Queue to dispatch job.}
15
    ';
16
17
    protected $description = 'Pull ipro availability';
18
19
    public function handle(): int
20
    {
21
        $months = (int) $this->option('months');
22
        if ($months < 0 || $months > 120) {
23
            $months = null;
24
        }
25
26
27
        if ($this->option('property_id')) {
28
            AvailabilityPull::dispatch(
29
                $this->option('property_id'),
30
                array_filter(['months' => $months])
31
            )->onQueue($this->option('queue'));
32
        } else {
33
            Property::query()
34
                    ->chunk(100, function ($properties) use ($months) {
35
                        /** @var Property $property */
36
                        foreach ($properties as $property) {
37
                            AvailabilityPull::dispatch(
38
                                $property->getKey(),
39
                                array_filter(['months' => $months])
40
                            )->onQueue($this->option('queue'));
41
                        }
42
                    });
43
        }
44
45
        return 0;
46
    }
47
}
48