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

CreateLocalConfigController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 33
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A options() 0 4 1
A beforeAction() 0 8 3
A actionInit() 0 11 2
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