Completed
Push — master ( 357d44...a482d1 )
by Eric
03:32
created

EditTaskCommand   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Importance

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

2 Methods

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