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

GenerateTask::addTask()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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