Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
ClientsSync
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace App\Console\Commands;
4
5use App\Services\GestionaClientSyncService;
6use Illuminate\Console\Command;
7
8class ClientsSync extends Command
9{
10    /**
11     * The name and signature of the console command.
12     *
13     * @var string
14     */
15    protected $signature = 'clients:sync {date?} {region?}';
16
17    /**
18     * The console command description.
19     *
20     * @var string
21     */
22    protected $description = 'Sync clients modified on a given date (default: yesterday) from Gestiona (G3W). Creates or updates local client records.';
23
24    /**
25     * Create a new command instance.
26     */
27    public function __construct(private readonly GestionaClientSyncService $syncService)
28    {
29        parent::__construct();
30    }
31
32    /**
33     * Execute the console command.
34     */
35    public function handle(): int
36    {
37        $date = $this->argument('date') ?? date('Y-m-d', strtotime('-1 day'));
38        $regions = $this->argument('region')
39            ? explode(',', $this->argument('region'))
40            : ['Cataluña', 'Madrid', 'Comunidad Valenciana', 'AndalucĂ­a', 'Baleares'];
41
42        return $this->syncService->runSync($date, $regions, $this);
43    }
44}