GettersTrait::getApp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * Automation tool mixed with code generator for easier continuous development
4
 *
5
 * @link      https://github.com/hiqdev/hidev
6
 * @package   hidev
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\base;
12
13
use Yii;
14
15
/**
16
 * Getters trait.
17
 */
18
trait GettersTrait
19
{
20
    protected $_view;
21
22
    public function getView()
23
    {
24
        if ($this->_view === null) {
25
            $this->_view = $this->getApp()->getView();
26
        }
27
28
        return $this->_view;
29
    }
30
31
    public function take($id)
32
    {
33
        return $this->getApp()->get($id);
34
    }
35
36
    public function getApp()
37
    {
38
        return Yii::$app;
39
    }
40
41
    /**
42
     * Runs given binary with given arguments.
43
     * Command output passes unchanged to console.
44
     * Returns exit code.
45
     * @param string $name
46
     * @param array|string $args
47
     * @return int exit code
48
     */
49
    public function passthru($name, $args = [])
50
    {
51
        return $this->take('binaries')->passthruBinary($name, $args);
52
    }
53
54
    /**
55
     * Runs given binary with given arguments. Returns stdout array.
56
     * @param string $name
57
     * @param string $args
58
     * @param bool $returnExitCode, default false
59
     * @return array|int stdout or exitcode
60
     */
61
    public function exec($name, $args = '', $returnExitCode = false)
62
    {
63
        return $this->take('binaries')->execBinary($name, $args, $returnExitCode);
64
    }
65
66
    public function execCode($name, $args = '')
67
    {
68
        return $this->take('binaries')->execBinary($name, $args, true);
69
    }
70
}
71