Completed
Push — master ( 2d9ef4...cff547 )
by he
05:48
created

GenerateTask   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 16
c 2
b 0
f 1
dl 0
loc 28
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addTask() 0 4 1
A handle() 0 15 3
1
<?php
2
3
namespace App\Console\Commands\Once;
4
5
use App\Entities\Solution;
6
use App\Task\SolutionServer;
7
use Illuminate\Console\Command;
8
9
class GenerateTask extends Command
10
{
11
    protected $signature = 'task:make {id}';
12
13
    protected $description = 'Generate Task by Solution Id';
14
15
    public function handle()
16
    {
17
        $id = $this->argument('id');
18
        app()->singleton(SolutionServer::class, function () {
19
            return new SolutionServer();
20
        });
21
        if (strpos($id, '-') !== false) {
0 ignored issues
show
Bug introduced by
It seems like $id can also be of type string[]; however, parameter $haystack of strpos() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

21
        if (strpos(/** @scrutinizer ignore-type */ $id, '-') !== false) {
Loading history...
22
            list($start, $end) = explode('-', $id, 2);
0 ignored issues
show
Bug introduced by
It seems like $id can also be of type string[]; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
            list($start, $end) = explode('-', /** @scrutinizer ignore-type */ $id, 2);
Loading history...
23
            $start = intval($start);
24
            $end = intval($end);
25
            for ($i = $start; $i <= $end; $i++) {
26
                $this->addTask($i);
27
            }
28
        } else {
29
            $this->addTask($id);
30
        }
31
    }
32
33
    private function addTask($id)
34
    {
35
        $solution = Solution::query()->findOrFail($id);
36
        app(SolutionServer::class)->add($solution)->send();
37
    }
38
}
39