AvailabilityPullCommand::handle()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 17
nc 4
nop 0
dl 0
loc 27
ccs 0
cts 18
cp 0
crap 30
rs 9.3888
c 0
b 0
f 0
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