Completed
Push — master ( e2bab1...fc7bc8 )
by Andrii
15:03
created

StartController::actionUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
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) 2014-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\controllers;
13
14
use hidev\base\File;
15
use Yii;
16
use yii\base\InvalidConfigException;
17
18
/**
19
 * Start goal.
20
 * Chdirs to the project's root directory and loads dependencies and configs.
21
 */
22
class StartController extends CommonController
23
{
24
    const MAIN_CONFIG = '.hidev/config.yml';
25
26
    public static $started = false;
27
28
    public function actionMake()
29
    {
30
        Yii::setAlias('@prjdir', $this->findDir());
31
        $this->takeConfig()->includeConfig(static::MAIN_CONFIG);
32
        $this->requireAll();
33
        $this->includeAll();
34
        self::$started = true;
35
    }
36
37
    public function actionUpdate()
38
    {
39
        return $this->passthru('composer', ['update', '-d', '.hidev', '--prefer-source', '--ansi']);
0 ignored issues
show
Documentation introduced by
array('update', '-d', '....efer-source', '--ansi') is of type array<integer,string,{"0..."string","4":"string"}>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
40
    }
41
42
    protected function requireAll()
43
    {
44
        $require = $this->takeConfig()->rawItem('require');
45
        if ($require) {
46
            $require['hiqdev/composer-extension-plugin'] = '*@dev';
47
            $saved = File::create('.hidev/composer.json')->save(compact('require'));
48
            if ($saved || !is_dir('.hidev/vendor')) {
49
                $this->runAction('update');
50
            }
51
            /// backup config then reset with extra config then restore
52
            $config = $this->takeConfig()->getItems();
53
            Yii::$app->clear('config');
54
            Yii::$app->loadExtraVendor('.hidev/vendor');
55
            $this->takeConfig()->mergeItems($config);
56
        }
57
    }
58
59
    /**
60
     * Include all configs.
61
     * @return void
62
     */
63
    public function includeAll()
64
    {
65
        $still = true;
66
        while ($still) {
67
            $still = false;
68
            $include = $this->takeConfig()->rawItem('include');
69
            if ($include) {
70
                foreach ($include as $path) {
71
                    $still = $still || $this->takeConfig()->includeConfig($path);
72
                }
73
            }
74
        }
75
    }
76
77
    /**
78
     * Chdirs to project's root by looking for config file in the current directory and up.
79
     * @throws InvalidConfigException when failed to find
80
     * @return string path to the root directory of hidev project
81
     */
82
    protected function findDir()
83
    {
84
        $configDir = '.hidev';
85
        for ($i = 0;$i < 9;++$i) {
86
            if (is_dir($configDir)) {
87
                return getcwd();
88
            }
89
            chdir('..');
90
        }
91
        throw new InvalidConfigException('Not a hidev project (or any of the parent directories). Use `hidev init` to initialize hidev project.');
92
    }
93
}
94