CreateTaskCommand   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
B handle() 0 13 5
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Console\Commands\Traits\AsksForUsers;
6
use App\Task;
7
use Illuminate\Console\Command;
8
use Mockery\Exception;
9
10
class CreateTaskCommand extends Command
11
{
12
    use AsksForUsers;
13
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'task:create {name? : The task name} {description? : The task description} {user_id? : The user id}';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Create a task';
27
28
    /**
29
     * Create a new command instance.
30
     *
31
     * @return void
32
     */
33
    public function __construct()
34
    {
35
        parent::__construct();
36
    }
37
38
    /**
39
     * Execute the console command.
40
     *
41
     * @return mixed
42
     */
43
    public function handle()
44
    {
45
        try {
46
            Task::create([
47
                'name'               => $this->argument('name') ? $this->argument('name') : $this->ask('Task name?'),
48
                'description'        => $this->argument('description') ? $this->argument('description') : $this->ask('Task description?'),
49
                'user_id'            => $this->argument('user_id') ? $this->argument('user_id') : $this->askForUsers(),
50
                'completed'          => false,
51
            ]);
52
        } catch (Exception $e) {
53
            $this->error('Error');
54
        }
55
        $this->info('Task has been added to database succesfully');
56
    }
57
}
58