CompleteTaskCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 4
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
/**
11
 * Class ShowTaskCommand.
12
 */
13
class CompleteTaskCommand extends Command
14
{
15
    use AsksForTasks;
16
17
    /**
18
     * The name and signature of the console command.
19
     *
20
     * @var string
21
     */
22
    protected $signature = 'task:complete {id? : The task id to change the status}';
23
24
    /**
25
     * The console command description.
26
     *
27
     * @var string
28
     */
29
    protected $description = 'Change the status of Complete from a task';
30
31
    /**
32
     * Execute the console command.
33
     *
34
     * @return mixed
35
     */
36
    public function handle()
37
    {
38
        try {
39
            $id = $this->argument('id') ? $this->argument('id') : $this->askForTasks();
40
            $task = Task::findOrFail($id);
41
            $task->update([
42
                'completed'        => $task->completed ? false : true,
43
            ]);
44
        } catch (Exception $e) {
45
            $this->error('Error');
46
        }
47
        $this->info('Task status has been edited to database succesfully');
48
    }
49
}
50