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.
Failure conditions met
Push6e6bc5...106abb
passed — Build
created

Installer::runComposerMethod()   A

↳ Parent: Installer

Complexity

Conditions 2
Paths 2

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 10
Code Lines 6

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 2
crap 2
1
<?php
2
3
/*
4
 * This file is part of Rocketeer
5
 *
6
 * (c) Maxime Fabre <ehtnam6@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 */
12
13
namespace Rocketeer\Tasks\Plugins;
14
15
use Rocketeer\Tasks\AbstractTask;
16
17
/**
18
 * Installs one or more plugins.
19
 */
20
class Installer extends AbstractTask
21
{
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Installs one or more plugins';
28
29
    /**
30
     * Whether to run the commands locally
31
     * or on the server.
32
     *
33
     * @var bool
34
     */
35
    protected $local = true;
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 8
    public function execute()
41
    {
42
        // Get package and destination folder
43 8
        $package = $this->getPackage();
44 8
        $method = $package ? 'require' : 'install';
45
46 8
        if (!$this->files->has($this->paths->getRocketeerPath().'/composer.json')) {
0 ignored issues
show
Documentation Bug introduced by Maxime Fabre
The method getRocketeerPath does not exist on object<Rocketeer\Service...Environment\Pathfinder>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
47 6
            $this->igniter->exportComposerFile();
48 6
        }
49
50
        // Install plugin
51 8
        $this->explainer->line($package ? 'Installing '.$package : 'Setting up Composer');
52 8
        $this->runComposerMethod($method, $package);
0 ignored issues
show
Bug introduced by Maxime Fabre
It seems like $package defined by $this->getPackage() on line 43 can also be of type array or null; however, Rocketeer\Tasks\Plugins\...er::runComposerMethod() does only seem to accept string|array<integer,string>, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
53 8
    }
54
55
    /**
56
     * @param string          $method
57
     * @param string|string[] $arguments
58
     */
59 8
    protected function runComposerMethod($method, $arguments)
60
    {
61 8
        $noDev = $method === 'install' ? '--no-dev' : '--update-no-dev';
62 8
        $options = [$noDev => '', '--working-dir' => $this->paths->getRocketeerPath()];
0 ignored issues
show
Documentation Bug introduced by Maxime Fabre
The method getRocketeerPath does not exist on object<Rocketeer\Service...Environment\Pathfinder>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
63 8
        $env = ['COMPOSER_DISCARD_CHANGES' => 1];
64
65
        // Install plugin
66 8
        $command = $this->composer()->$method($arguments, $options, $env);
67 8
        $this->run($this->shellCommand($command));
0 ignored issues
show
Documentation Bug introduced by Maxime Fabre
The method shellCommand does not exist on object<Rocketeer\Tasks\Plugins\Installer>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
68 8
    }
69
70
    /**
71
     * @return array|null|string
72
     */
73 8
    protected function getPackage()
74
    {
75 8
        return array_key_exists('package', $this->command->getInput()->getArguments())
76 8
            ? $this->command->argument('package')
77 8
            : null;
78
    }
79
}
80