DeleteTaskCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 10 3
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Console\Commands\Traits\AsksForTasks;
6
use App\Task;
7
use Illuminate\Console\Command;
8
use Mockery\Exception;
9
10
class DeleteTaskCommand extends Command
11
{
12
    use AsksForTasks;
13
14
    /**
15
     * The name and signature of the console command.
16
     *
17
     * @var string
18
     */
19
    protected $signature = 'task:delete {id? : The task id}';
20
21
    /**
22
     * The console command description.
23
     *
24
     * @var string
25
     */
26
    protected $description = 'Delete 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
            $id = $this->argument('id') ? $this->argument('id') : $this->askForTasks();
47
            $task = Task::findOrFail($id);
48
            $task->delete();
49
        } catch (Exception $e) {
50
            $this->error('Error');
51
        }
52
        $this->info('Task has been deleted to database succesfully');
53
    }
54
}
55