Passed
Push — master ( 823e5a...6ca56e )
by Quim González
04:15
created

ListUserCommand::handle()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 4
nop 0
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\User;
6
use Illuminate\Console\Command;
7
8 View Code Duplication
class ListUserCommand extends Command
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * The name and signature of the console command.
12
     *
13
     * @var string
14
     */
15
    protected $signature = 'user:list';
16
17
    /**
18
     * The console command description.
19
     *
20
     * @var string
21
     */
22
    protected $description = 'List all users 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
        try {
42
            $tasks = User::all()->toArray();
43
            $headers = array_keys($tasks[0]);
0 ignored issues
show
Bug introduced by
$tasks[0] of type App\User 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

43
            $headers = array_keys(/** @scrutinizer ignore-type */ $tasks[0]);
Loading history...
44
45
            $this->table($headers, $tasks);
46
        } 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...
47
            $this->error('Error: '.$e);
48
        }
49
    }
50
}
51