GenerateConfigWizard   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 18
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 17 2
A getFromStdin() 0 5 2
1
<?php
2
3
namespace Vados\MigrationRunner\command;
4
5
use Vados\MigrationRunner\providers\PathProvider;
6
7
/**
8
 * Class GenerateConfigWizard
9
 * @package Vados\MigrationRunner\command
10
 */
11
class GenerateConfigWizard implements ICommand
12
{
13
    public function run()
14
    {
15
        $config = [];
16
        echo 'Enter database adapter (default: sqlite): ';
17
        $this->getFromStdin($config['adapter'], 'sqlite');
18
        if ('sqlite' !== $config['adapter']) {
19
            echo 'Enter database host (default: localhost): ';
20
            $this->getFromStdin($config['host'], 'localhost');
21
            echo 'Enter username (default: root): ';
22
            $this->getFromStdin($config['username'], 'root');
23
            echo 'Enter password (default: root): ';
24
            $this->getFromStdin($config['password'], 'root');
25
        }
26
        echo 'Enter database name (default: phalcon): ';
27
        $this->getFromStdin($config['dbname'], 'phalcon');
28
        file_put_contents(PathProvider::getConfig(), '<?php return ' . var_export($config, true) . ';');
29
        echo 'Config generated in ' . PathProvider::getConfig() . PHP_EOL;
30
    }
31
32
    /**
33
     * @var $field
34
     * @var $default
35
     */
36
    protected function getFromStdin(&$field, $default = null)
37
    {
38
        $field = trim(fgets(STDIN));
39
        if (!$field) {
40
            $field = $default;
41
        }
42
    }
43
}