ParseReportsCommand::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 10
cts 10
cp 1
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types=1);
3
4
namespace agoalofalife\Reports\Console;
5
6
use agoalofalife\Reports\Models\Report;
7
use Illuminate\Console\Command;
8
9
/**
10
 * Class ParseReportsCommand
11
 * @package agoalofalife\Reports\Console
12
 */
13
class ParseReportsCommand extends Command
14
{
15
    /**
16
     * The name and signature of the console command.
17
     *
18
     * @var string
19
     */
20
    protected $signature = 'reports:parse';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Search reports which status is "process"';
28
    /**
29
     * Execute the console command.
30
     *
31
     * @return mixed
32
     */
33 2
    public function handle() : void
34
    {
35 2
        $reportInProcess = Report::where('status', Report::STATUS_PROCESS)->get();
36
37 2
        if ($reportInProcess->count() > 0) {
38 1
            $reportInProcess = $reportInProcess->random();
39 1
            $reportInProcess->update([
40 1
                'pid' => getmypid(),
41 1
                'status' => Report::STATUS_WORKER
42
            ]);
43 1
            $this->call('reports:handle', ['classReport' => $reportInProcess->class_name]);
44
        } else {
45 1
            $this->warn('Reports in the status "in process" is missing');
46
        }
47
    }
48
}