Completed
Push — master ( 97b162...4ff1cb )
by Igor
15:16
created

CreateLocalConfigController::actionIndex()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 12
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 8
nc 2
nop 0
crap 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
{
15
    /**
16
     * @var string
17
     */
18
    public $path;
19
20
    /**
21
     * @SuppressWarnings(PHPMD.UnusedFormalParameter)
22
     */
23 1
    public function options($actionId = '')
24
    {
25 1
        return ['path'];
26
    }
27
28 2
    public function beforeAction($action)
29
    {
30 2
        if (parent::beforeAction($action)) {
31 2
            if (empty($this->path)) {
32 1
                throw new InvalidConfigException('`path` should be specified');
33
            }
34
        }
35 1
        return true;
36
    }
37
38
    /**
39
     * @SuppressWarnings(PHPMD.ElseExpression)
40
     */
41 1
    public function actionIndex()
42
    {
43 1
        $source = Yii::getAlias('@app/config/config.local');
44 1
        $dist = Yii::getAlias($this->path);
45
46 1
        if (!file_exists($dist)) {
47 1
            copy($source, $dist);
48 1
            $this->stdout("Created successfully!\n", Console::FG_GREEN);
49
        } else {
50
            $this->stdout("Config file is exist!\n", Console::FG_RED); // @codeCoverageIgnore
51
        }
52 1
    }
53
}
54