Completed
Push — master ( 395fb2...b0764c )
by he
10:48 queued 10s
created

GenerateTask::handle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace App\Console\Commands\Once;
4
5
use App\Entities\Solution;
6
use App\Task\Task;
7
use App\Task\TaskQueue;
8
use Illuminate\Console\Command;
9
10
class GenerateTask extends Command
11
{
12
    protected $signature = 'task:make {id}';
13
14
    protected $description = 'Generate Task by Solution Id';
15
16
    public function handle()
17
    {
18
        $solution = $this->getSolution();
19
        $task = $this->generateTask($solution);
20
21
        $this->send($task);
22
    }
23
24
    /**
25
     * @return Solution
26
     */
27
    private function getSolution()
28
    {
29
        $id = $this->argument('id');
30
31
        return Solution::query()->findOrFail($id);
32
    }
33
34
    private function generateTask(Solution $solution)
35
    {
36
        $task = app(Task::class);
37
        $task->setSolution($solution);
38
        $task->setProblem($solution->problem);
39
40
        return $task;
41
    }
42
43
    private function send($task)
44
    {
45
        $queue = app(TaskQueue::class);
46
        $queue->add($task);
47
        $queue->close();
48
    }
49
}
50