ListTasksCommand   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 20 4
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Task;
6
use App\User;
7
use Illuminate\Console\Command;
8
use Mockery\Exception;
9
10
class ListTasksCommand extends Command
11
{
12
    /**
13
     * The name and signature of the console command.
14
     *
15
     * @var string
16
     */
17
    protected $signature = 'task:list';
18
19
    /**
20
     * The console command description.
21
     *
22
     * @var string
23
     */
24
    protected $description = 'List all tasks';
25
26
    /**
27
     * Create a new command instance.
28
     *
29
     * @return void
30
     */
31
    public function __construct()
32
    {
33
        parent::__construct();
34
    }
35
36
    /**
37
     * Execute the console command.
38
     *
39
     * @return mixed
40
     */
41
    public function handle()
42
    {
43
        try {
44
            $tasks = Task::all();
45
46
            $headers = ['id', 'Name', 'Completed', 'User id', 'User Name'];
47
            $fields = [];
48
            foreach ($tasks as $task) {
49
                $fields[] = [
50
                    'id:'               => $task->id,
51
                    'Name:'             => $task->name,
52
                    'Completed:'        => $task->completed ? 'Yes' : 'No',
53
                    'User id:'          => $task->user_id,
54
                    'User name:'        => User::findOrFail($task->user_id)->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...
55
                ];
56
            }
57
        } catch (Exception $e) {
58
            $this->error('Error');
59
        }
60
        $this->table($headers, $fields);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $headers does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $fields does not seem to be defined for all execution paths leading up to this point.
Loading history...
61
    }
62
}
63