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.

Composer::getPackages()   C
last analyzed

Complexity

Conditions 7
Paths 6

Size

Total Lines 30
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 18
nc 6
nop 0
dl 0
loc 30
rs 6.7272
c 0
b 0
f 0
1
<?php
2
/**
3
 * See class comment
4
 *
5
 * PHP Version 5
6
 *
7
 * @category   Netresearch
8
 * @package    Netresearch\Kite
9
 * @subpackage Service
10
 * @author     Christian Opitz <[email protected]>
11
 * @license    http://www.netresearch.de Netresearch Copyright
12
 * @link       http://www.netresearch.de
13
 */
14
15
namespace Netresearch\Kite\Service;
16
use Netresearch\Kite\Job;
17
use Netresearch\Kite\Service\Composer\Package;
18
use Netresearch\Kite\Task;
19
use Netresearch\Kite\Exception;
20
use Netresearch\Kite\Tasks;
21
22
/**
23
 * Composer service
24
 *
25
 * @category   Netresearch
26
 * @package    Netresearch\Kite
27
 * @subpackage Service
28
 * @author     Christian Opitz <[email protected]>
29
 * @license    http://www.netresearch.de Netresearch Copyright
30
 * @link       http://www.netresearch.de
31
 */
32
class Composer extends Tasks
33
{
34
    /**
35
     * @var bool
36
     */
37
    protected $tasksInvalid = true;
38
39
    /**
40
     * Job constructor.
41
     *
42
     * @param Job $job The job
43
     */
44
    public function __construct(Job $job)
45
    {
46
        parent::__construct($job);
47
        $this->run();
48
    }
49
50
    /**
51
     * Invalidate the packages
52
     *
53
     * @return void
54
     */
55
    public function invalidatePackages()
56
    {
57
        $this->tasksInvalid = true;
58
    }
59
60
    /**
61
     * Get a variable (second argument can be a default value)
62
     *
63
     * @param string $name The variable name
64
     *
65
     * @return mixed
66
     */
67
    public function &offsetGet($name)
68
    {
69
        if ($this->tasksInvalid && in_array($name, array('packages', 'rootPackage'), true)) {
70
            $this->tasksInvalid = false;
71
            $packages = $this->getPackages();
72
            parent::offsetSet('packages', $packages);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (offsetSet() instead of offsetGet()). Are you sure this is correct? If so, you might want to change this to $this->offsetSet().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
73
            parent::offsetSet('rootPackage', reset($packages));
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (offsetSet() instead of offsetGet()). Are you sure this is correct? If so, you might want to change this to $this->offsetSet().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
74
        }
75
        return parent::offsetGet($name);
76
    }
77
78
    /**
79
     * Determine if a variable is available on this very object
80
     *
81
     * @param mixed $offset Variable name
82
     *
83
     * @internal See {@see Variables::offsetGet()}
84
     *
85
     * @return boolean
86
     */
87
    public function offsetExists($offset)
88
    {
89
        return in_array($offset, array('packages', 'rootPackage')) || parent::offsetExists($offset);
90
    }
91
92
93
    /**
94
     * Get all packages
95
     *
96
     * @return array
97
     */
98
    protected function getPackages()
99
    {
100
        $packages = array();
101
102
        $this->output('<step>Gathering composer package information</step>');
103
104
        $composerJson = new Package($this, 'composer.json', true);
105
        if (!isset($composerJson->name)) {
106
            throw new Exception('No name for project found in composer.json');
107
        }
108
        $packages[$composerJson->name] = $composerJson;
109
110
        if (!file_exists('composer.lock')) {
111
            throw new Exception('Please install application first');
112
        }
113
        $composerLock = json_decode(file_get_contents('composer.lock'));
114
115
        $packagePaths = $this->composer('show', '--installed --path --no-ansi', array('pt' => false));
116
        foreach (explode("\n", $packagePaths) as $line) {
117
            list($packageName, $packagePath) = preg_split('/\s+/', $line, 2);
118
            foreach ($composerLock->packages as $package) {
119
                if ($package->name === $packageName && $package->type !== 'metapackage') {
120
                    $package->path = $packagePath;
121
                    $packages[$packageName] = new Package($this, $package);
122
                }
123
            }
124
        }
125
126
        return $packages;
127
    }
128
}
129
?>
130