Completed
Push — master ( d24069...59bb94 )
by Andrii
03:18
created

CommandController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 7
c 2
b 0
f 0
lcom 2
cbo 2
dl 0
loc 38
ccs 0
cts 25
cp 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setCommands() 0 4 1
A actionSave() 0 10 4
A actionBefore() 0 6 1
A actionAfter() 0 5 1
1
<?php
2
3
/*
4
 * Task runner, code generator and build tool for easier continuos integration
5
 *
6
 * @link      https://github.com/hiqdev/hidev
7
 * @package   hidev
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\controllers;
13
14
use Yii;
15
16
/**
17
 * Command controller.
18
 */
19
class CommandController extends CommonController
20
{
21
    public $path;
22
    public $sudo;
23
    public $command;
24
    public $comment;
25
26
    protected $_cwd;
27
28
    public function setCommands($value)
29
    {
30
        $this->command = $value;
31
    }
32
33
    public function actionSave()
34
    {
35
        $commands = explode("\n", $this->command);
36
        foreach ($commands as $command) {
37
            $command = trim($command);
38
            if ($command) {
39
                passthru(($this->sudo ? 'sudo ' : '') . $command);
40
            }
41
        }
42
    }
43
44
    public function actionBefore()
45
    {
46
        $this->_cwd = getcwd();
47
        chdir(Yii::getAlias($this->path));
48
        parent::actionBefore();
49
    }
50
51
    public function actionAfter()
52
    {
53
        parent::actionAfter();
54
        chdir($this->_cwd);
55
    }
56
}
57