Completed
Push — master ( c96dfb...142578 )
by Igor
12:57 queued 10:25
created

CreateLocalConfigController   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
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 41
ccs 16
cts 16
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 9 3
A actionInit() 0 12 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 1
        }
35 1
        return true;
36
    }
37
38
    /**
39
     * @SuppressWarnings(PHPMD.ElseExpression)
40
     */
41 1
    public function actionInit()
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 1
        } else {
50
            $this->stdout("Config file is exist!\n", Console::FG_RED); // @codeCoverageIgnore
51
        }
52 1
    }
53
}
54