Completed
Push — master ( 069462...8b5285 )
by Eric
03:11
created

CompleteTaskCommand::handle()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 1
b 0
f 0
nc 8
nop 0
dl 0
loc 12
rs 9.2
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Console\Commands\Traits\AsksForTasks;
6
use App\Task;
7
use App\User;
8
use Illuminate\Console\Command;
9
use Mockery\Exception;
10
11
/**
12
 * Class ShowTaskCommand.
13
 */
14
class CompleteTaskCommand extends Command
15
{
16
    use AsksForTasks;
17
18
    /**
19
     * The name and signature of the console command.
20
     *
21
     * @var string
22
     */
23
    protected $signature = 'task:complete {id? : The task id to change the status}';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = 'Change the status of Complete from a task';
31
32
    /**
33
     * Execute the console command.
34
     *
35
     * @return mixed
36
     */
37
    public function handle()
38
    {
39
        try {
40
            $id = $this->argument('id') ? $this->argument('id') : $this->askForTasks();
41
            $task = Task::findOrFail($id);
42
            $task->update([
43
                'completed'        => $task->completed?false:true,
44
            ]);
45
        } catch (Exception $e) {
46
            $this->error('Error');
47
        }
48
        $this->info('Task status has been edited to database succesfully');
49
    }
50
}
51