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

ShowTaskCommand::handle()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 21
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 14
c 1
b 0
f 0
nc 8
nop 0
dl 0
loc 21
rs 9.0534
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 ShowTaskCommand 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:show {id? : The task id to edit}';
24
25
    /**
26
     * The console command description.
27
     *
28
     * @var string
29
     */
30
    protected $description = 'Show an task';
31
32
    /**
33
     * Execute the console command.
34
     *
35
     * @return mixed
36
     */
37
    public function handle()
38
    {
39
        $id = $this->argument('id') ? $this->argument('id') : $this->askForTasks();
40
        $task = Task::findOrFail($id);
41
        $user = User::findOrFail($task->user_id);
42
43
        $this->info('Task:');
44
45
        try {
46
            $headers = ['Key', 'Value'];
47
48
            $fields = [
49
              ['Name:', $task->name],
50
                ['Completed:', $task->completed?'Yes':'No',],
51
              ['User id:', $task->user_id],
52
              ['User name:', $user->name],
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on App\User. Since you implemented __get, consider adding a @property annotation.
Loading history...
53
            ];
54
55
            $this->table($headers, $fields);
56
        } catch (Exception $e) {
57
            $this->error('Error');
58
        }
59
    }
60
}
61