DatabaseConnectionCommand   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 49
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 30 4
1
<?php
2
3
namespace Epesi\Core\Console;
4
5
use Illuminate\Console\Command;
6
7
class DatabaseConnectionCommand extends Command
8
{
9
    /**
10
     * The name and signature of the console command.
11
     *
12
     * @var string
13
     */
14
    protected $signature = 'epesi:database-connection {--connection= : DB connection settings}';
15
16
    /**
17
     * The console command description.
18
     *
19
     * @var string
20
     */
21
    protected $description = 'Update database connection for epesi application';
22
    
23
    /**
24
     * Execute the console command.
25
     */
26
    public function handle()
27
    {
28
    	$connection = $this->option('connection');
29
    	
30
		$map = [
31
				'driver' => 'DB_CONNECTION',
32
				'host' => 'DB_HOST',
33
				'port' => 'DB_PORT',
34
				'database' => 'DB_DATABASE',
35
				'username' => 'DB_USERNAME',
36
				'password' => 'DB_PASSWORD',
37
		];
38
		
39
		$env = [];
40
		foreach ($map as $key => $name) {
41
			if (!isset($connection[$key])) continue;
42
			
43
			$env[$name] = $connection[$key];
44
		}
45
		
46
		if (!$env) {
47
			$this->comment('No DB connection settings to update!');
48
			return;
49
		}
50
    	
51
    	$this->call('epesi:env', [
52
    			'name' => $env
53
    	]);
54
    	
55
    	$this->comment('DB connection settings updated!');
56
    }
57
}
58