GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

ExtensionController   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 5
dl 0
loc 59
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A actionInstall() 0 12 2
A actionUninstall() 0 22 5
A checkInJson() 0 19 6
1
<?php
2
3
namespace app\commands;
4
5
use app\modules\core\models\Extensions;
6
use Yii;
7
use yii\console\Controller;
8
use yii\helpers\ArrayHelper;
9
use yii\helpers\Json;
10
use yii\helpers\Console;
11
12
class ExtensionController extends Controller
13
{
14
15
    public function actionInstall($package)
16
    {
17
        $installed = Extensions::isPackageInstalled($package);
0 ignored issues
show
Unused Code introduced by
$installed is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
18
19
        if ($path = $this->checkInJson($package, true)) {
20
            // it's in studio
21
            Extensions::installStudioPackage($package, $path);
22
        } else {
23
            // it's in composer
24
            Extensions::installExtension($package, !$this->checkInJson($package, false));
25
        }
26
    }
27
28
    public function actionUninstall($package)
0 ignored issues
show
Unused Code introduced by
The parameter $package 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...
29
    {
30
        $this->stderr('Not working now');
31
        return 1;
32
        $extension = Extensions::findByName($package);
0 ignored issues
show
Unused Code introduced by
$extension = \app\module...::findByName($package); does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
33
        if ($extension === null) {
34
            $this->stderr('[ Error ] Extension is not installed', Console::FG_RED);
35
            return 1;
36
        }
37
        if ($extension->deactivateExtension() === false) {
38
            $this->stderr('[ Error ] Could not deactivate extension', Console::FG_RED);
39
            return 2;
40
        }
41
        if ($this->checkInJson($package, true) === false) {
42
            // we don't remove packages in studio.json - only composer
43
            if ($extension->removeExtensionPackage() === false) {
44
                $this->stderr('[ Error ] Could not remove extension package', Console::FG_RED);
45
                return 3;
46
            }
47
        }
48
        $this->stdout('[ OK ] Extension uninstalled', Console::FG_RED);
49
    }
50
51
    private function checkInJson($package, $studio=false)
52
    {
53
        if ($studio === true) {
54
            $fn = Yii::getAlias('@app/studio.json');
55
        } else {
56
            $fn = Yii::getAlias('@app/composer.json');
57
        }
58
        if (file_exists($fn) === false) {
59
            return false;
60
        }
61
        $json = Json::decode(file_get_contents($fn));
62
        if ($studio === true && isset($json['packages'])) {
63
64
            return ArrayHelper::getValue($json['packages'], $package, false);
65
        } elseif ($studio === false) {
66
            return ArrayHelper::getValue($json['require'], $package, false);
67
        }
68
69
    }
70
}