Completed
Push — master ( 53e22b...6229cb )
by Andrii
13:25
created

ComposerController   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 12
c 3
b 0
f 0
lcom 2
cbo 2
dl 0
loc 61
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A actionInstall() 0 4 1
A actionUpdate() 0 4 1
A actionSelfUpdate() 0 4 1
A actionDoInstall() 0 6 2
A actionDoUpdate() 0 4 1
A run() 0 12 3
A getNamespace() 0 4 1
A getFullName() 0 4 1
A getConfiguration() 0 6 1
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, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\composer\controllers;
13
14
use Yii;
15
16
/**
17
 * Goal for Composer.
18
 */
19
class ComposerController extends \hidev\controllers\CommonController
20
{
21
    protected $_before = ['composer.json'];
22
23
    public function actionInstall()
24
    {
25
        return $this->runActions(['before', 'do-install', 'after']);
26
    }
27
28
    public function actionUpdate()
29
    {
30
        return $this->runActions(['before', 'do-update', 'after']);
31
    }
32
33
    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...
34
    {
35
        return $this->run('self-update', '');
36
    }
37
38
    public function actionDoInstall()
39
    {
40
        $dir = Yii::getAlias('@prjdir/vendor');
41
42
        return is_dir($dir) ? 0 : $this->run('install');
43
    }
44
45
    public function actionDoUpdate()
46
    {
47
        return $this->run('update');
48
    }
49
50
    public function run($command, $dir = null)
51
    {
52
        if ($dir === null) {
53
            $dir = Yii::getAlias('@prjdir');
54
        }
55
        $args = [$command, '--ansi'];
56
        if ($dir) {
57
            $args[] = '-d';
58
            $args[] = $dir;
59
        }
60
        return $this->passthru('composer', $args);
0 ignored issues
show
Documentation introduced by
$args is of type array<integer,?>, 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...
61
    }
62
63
    public function getNamespace()
64
    {
65
        return @trim(key($this->getConfiguration()->getFile()->get('autoload')['psr-4']), '\\');
66
    }
67
68
    public function getFullName()
69
    {
70
        return $this->getConfiguration()->getFullName();
71
    }
72
73
    public function getConfiguration()
74
    {
75
        $conf = $this->takeGoal('composer.json');
76
        $conf->runAction('load');
77
        return $conf;
78
    }
79
}
80