Completed
Pull Request — master (#32)
by
unknown
01:33
created

Mysql   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4
1
<?php
2
3
namespace Recca0120\Terminal\Console\Commands;
4
5
use Illuminate\Support\Arr;
6
use Illuminate\Console\Command;
7
use Illuminate\Database\DatabaseManager;
8
use Recca0120\Terminal\Contracts\WebCommand;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class Mysql extends Command implements WebCommand
12
{
13
    /**
14
     * The console command name.
15
     *
16
     * @var string
17
     */
18
    protected $name = 'mysql';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'mysql console';
26
27
    /**
28
     * $connection.
29
     *
30
     * @var \Illuminate\Database\DatabaseManager
31
     */
32
    protected $databaseManager;
33
34
    /**
35
     * __construct.
36
     *
37
     * @param \Illuminate\Database\DatabaseManager $databaseManager
38
     */
39 1
    public function __construct(DatabaseManager $databaseManager)
40
    {
41 1
        parent::__construct();
42
43 1
        $this->databaseManager = $databaseManager;
44 1
    }
45
46
    /**
47
     * Handle the command.
48
     *
49
     * @throws \InvalidArgumentException
50
     */
51 1
    public function handle()
52
    {
53 1
        $query = $this->option('command');
54 1
        if(isset(config('terminal.dbconnection')) {
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '{'
Loading history...
Bug introduced by
Avoid IF statements that are always true or false
Loading history...
55 1
            $connection = $this->databaseManager->connection(config('terminal.dbconnection'));
56 1
        } else {
57 1
            $connection = $this->databaseManager->connection();
58 1
        }
59
        $rows = json_decode(json_encode($connection->select($query)), true);
60
        $headers = array_keys(Arr::get($rows, 0, []));
61
        $this->table($headers, $rows);
62
    }
63
64
    /**
65 1
     * Get the console command options.
66
     *
67
     * @return array
68 1
     */
69 1
    protected function getOptions()
70
    {
71
        return [
72
            ['command', null, InputOption::VALUE_OPTIONAL],
73
        ];
74
    }
75
}
76