Completed
Push — master ( e02cbc...0dd416 )
by Andrii
13:13
created

ComposerController::doUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * Composer plugin for HiDev
5
 *
6
 * @link      https://github.com/hiqdev/hidev-composer
7
 * @package   hidev-composer
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\composer\console;
13
14
use Yii;
15
16
/**
17
 * Composer.
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class ComposerController extends \hidev\base\Controller
21
{
22
    protected $_before = ['composer.json'];
23
24
    /**
25
     * Does `composer install`
26
     */
27
    public function actionIndex()
28
    {
29
        return $this->doInstall();
30
    }
31
32
    /**
33
     * Does `composer install`
34
     */
35
    public function actionInstall()
36
    {
37
        return $this->doInstall();
38
    }
39
40
    /**
41
     * Does `composer install`
42
     */
43
    public function actionUpdate()
44
    {
45
        return $this->doUpdate();
46
    }
47
48
    /**
49
     * Does `composer self-update`
50
     */
51
    public function actionSelfUpdate($version = null)
0 ignored issues
show
Unused Code introduced by
The parameter $version is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
52
    {
53
        return $this->run('self-update', '');
54
    }
55
56
    public function doInstall()
57
    {
58
        $dir = Yii::getAlias('@root/vendor');
59
60
        return is_dir($dir) ? 0 : $this->run('install');
61
    }
62
63
    public function doUpdate()
64
    {
65
        return $this->run('update');
66
    }
67
68
    public function run($command, $dir = null)
69
    {
70
        if ($dir === null) {
71
            $dir = Yii::getAlias('@root');
72
        }
73
        $args = [$command, '--ansi'];
74
        if ($dir && $dir !== getcwd()) {
75
            $args[] = '-d';
76
            $args[] = $dir;
77
        }
78
79
        return $this->passthru('composer', $args);
80
    }
81
}
82