Binaries   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 50
ccs 0
cts 26
cp 0
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A passthruBinary() 0 3 1
A execBinary() 0 3 1
A actionMake() 0 7 4
A getItemConfig() 0 7 1
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\components;
12
13
use hidev\base\BinaryPhp;
14
15
class Binaries extends \hidev\base\Component
16
{
17
    use \hiqdev\yii2\collection\ManagerTrait;
18
19
    public $defaultClass = BinaryPhp::class;
20
21
    public function actionMake()
22
    {
23
        foreach ($this->getItems() as $name => $bin) {
24
            if (!$bin->detectPath($name)) {
25
                $exitcode = $bin->install();
26
                if ($exitcode) {
27
                    return $exitcode;
28
                }
29
            }
30
        }
31
    }
32
33
    /**
34
     * Prepares item config.
35
     */
36
    public function getItemConfig($name = null, array $config = [])
37
    {
38
        return array_merge([
39
            'name'  => $name,
40
            'class' => $this->defaultClass,
41
            'binaries' => $this,
42
        ], $config);
43
    }
44
45
    /**
46
     * Prepares and runs with passthru. Returns exit code.
47
     * @param string $name binary
48
     * @param array|string $args
49
     * @return int exit code
50
     */
51
    public function passthruBinary($name, $args = [])
52
    {
53
        return $this->get($name)->passthru($args);
54
    }
55
56
    /**
57
     * Prepares and runs with exec. Returns stdout string.
58
     * @param string $name binary
59
     * @param string $args
60
     * @return array stdout
61
     */
62
    public function execBinary($name, $args = '', $returnExitCode = false)
63
    {
64
        return $this->get($name)->exec($args, $returnExitCode);
65
    }
66
}
67