ListTaskCommand   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 12 2
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Task;
6
use Illuminate\Console\Command;
7
8
class ListTaskCommand extends Command
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'task:list';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'List all tasks with a table format.';
23
24
    /**
25
     * Create a new command instance.
26
     *
27
     * @return void
28
     */
29
    public function __construct()
30
    {
31
        parent::__construct();
32
    }
33
34
    /**
35
     * Execute the console command.
36
     *
37
     * @return mixed
38
     */
39
    public function handle()
40
    {
41
42
        //$headers = ['id','name','created_at','updated_at'];
43
44
        try {
45
            $tasks = Task::all()->toArray();
46
            $headers = array_keys($tasks[0]);
0 ignored issues
show
Bug introduced by
$tasks[0] of type App\Task is incompatible with the type array expected by parameter $input of array_keys(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

46
            $headers = array_keys(/** @scrutinizer ignore-type */ $tasks[0]);
Loading history...
47
48
            $this->table($headers, $tasks);
49
        } catch (exception $e) {
0 ignored issues
show
Bug introduced by
The type App\Console\Commands\exception was not found. Did you mean exception? If so, make sure to prefix the type with \.
Loading history...
50
            $this->error('Error: '.$e);
51
        }
52
    }
53
}
54