Completed
Push — master ( b59e75...1e97db )
by Igor
12:04
created

CreateLocalConfigController::actionInit()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 0
crap 6
1
<?php
2
3
namespace app\commands;
4
5
use Yii;
6
use yii\base\InvalidConfigException;
7
use yii\console\Controller;
8
use yii\helpers\Console;
9
10
/**
11
 * Command for create local config
12
 */
13
class CreateLocalConfigController extends Controller
14 1
{
15
    /**
16 1
     * @var string
17 1
     */
18 1
    public $path;
19
20 1
    public function options()
21
    {
22
        return ['path'];
23 1
    }
24
25
    public function beforeAction($action)
26
    {
27
        if (parent::beforeAction($action)) {
28
            if (empty($this->path)) {
29
                throw new InvalidConfigException('`path` should be specified');
30
            }
31
        }
32
    }
33
34
    public function actionInit()
35
    {
36
        $source = Yii::getAlias('@app/config/config.local');
37
        $dist = Yii::getAlias($this->path);
38
39
        if (!file_exists($dist)) {
40
            copy($source, $dist);
41
            return $this->stdout("Created successfully!\n", Console::FG_GREEN);
42
        }
43
        return $this->stdout("Config file is exist!\n", Console::FG_RED); // @codeCoverageIgnore
44
    }
45
}
46