ComposerController   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 64
ccs 0
cts 21
cp 0
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A actionInstall() 0 4 1
A actionUpdate() 0 4 1
A actionSelfUpdate() 0 4 1
A actionDumpAutoload() 0 4 1
A doInstall() 0 6 2
A doUpdate() 0 4 1
A run() 0 13 4
1
<?php
2
/**
3
 * HiDev plugin for Composer.
4
 *
5
 * @link      https://github.com/hiqdev/hidev-composer
6
 * @package   hidev-composer
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2015-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\composer\console;
12
13
use Yii;
14
15
/**
16
 * Composer.
17
 * @author Andrii Vasyliev <[email protected]>
18
 */
19
class ComposerController extends \hidev\base\Controller
20
{
21
    protected $_before = ['composer.json'];
22
23
    public $defaultAction = 'install';
24
25
    /**
26
     * Does `composer install`.
27
     */
28
    public function actionInstall()
29
    {
30
        return $this->doInstall();
31
    }
32
33
    /**
34
     * Does `composer install`.
35
     */
36
    public function actionUpdate()
37
    {
38
        return $this->doUpdate();
39
    }
40
41
    /**
42
     * Does `composer self-update`.
43
     */
44
    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...
45
    {
46
        return $this->run('self-update', '');
47
    }
48
49
    /**
50
     * Does `composer dump-autoload`.
51
     */
52
    public function actionDumpAutoload()
53
    {
54
        return $this->run('dump-autoload');
55
    }
56
57
    public function doInstall()
58
    {
59
        $dir = Yii::getAlias('@root/vendor');
60
61
        return is_dir($dir) ? 0 : $this->run('install');
62
    }
63
64
    public function doUpdate()
65
    {
66
        return $this->run('update');
67
    }
68
69
    public function run($command, $dir = null)
70
    {
71
        if ($dir === null) {
72
            $dir = Yii::getAlias('@root');
73
        }
74
        $args = [$command, '--ansi'];
75
        if ($dir && $dir !== getcwd()) {
76
            $args[] = '-d';
77
            $args[] = $dir;
78
        }
79
80
        return $this->passthru('composer', $args);
81
    }
82
}
83