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.

ListProjectsCommand::initialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 7
ccs 0
cts 5
cp 0
rs 9.4285
c 1
b 0
f 1
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * This file is part of the Gerrie package.
4
 *
5
 * (c) Andreas Grunwald <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Gerrie\Command;
12
13
use Gerrie\Component\Configuration\ConfigurationFactory;
14
use Gerrie\API\DataService\DataServiceFactory;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\Console\Output\OutputInterface;
17
18
class ListProjectsCommand extends GerrieBaseCommand
19
{
20
21
    /**
22
     * Configuration object
23
     *
24
     * @var \Gerrie\Component\Configuration\Configuration
25
     */
26
    protected $configuration = null;
27
28
    protected function configure()
29
    {
30
        $this
31
            ->setName('gerrie:list-projects')
32
            ->setDescription('List/Displays all projects of a Gerrit instance');
33
34
        $this->addConfigFileOption();
35
        $this->addSSHKeyOption();
36
        $this->addInstancesArgument();
37
    }
38
39
    protected function initialize(InputInterface $input, OutputInterface $output)
40
    {
41
        /** @var InputExtendedInterface $input */
42
43
        $configFile = $input->getOption('config-file');
44
        $this->configuration = ConfigurationFactory::getConfigurationByConfigFileAndCommandOptionsAndArguments($configFile, $input);
45
    }
46
47
    protected function execute(InputInterface $input, OutputInterface $output)
48
    {
49
        /** @var InputExtendedInterface $input */
50
51
        // Start the importer for each configured project
52
        $gerritSystems = $this->configuration->getConfigurationValue('Gerrit');
53
        $defaultSSHKeyFile = $this->configuration->getConfigurationValue('SSH.KeyFile');
54
55
        $i = 0;
56
        foreach ($gerritSystems as $name => $gerrieProject) {
57
58
            foreach ($gerrieProject as $gerritInstance) {
59
                $path = parse_url($gerritInstance);
60
61
                // TODO Extract this Instance Key part here. This is the same as in "CrawlCommand".
62
                // Get instance url
63
                // If the instance is a string, we only got a url path like scheme://user@url:port/
64
                if (is_string($gerritInstance)) {
65
                    $instanceConfig = [
66
                        'Instance' => $gerritInstance,
67
                        'KeyFile' => $defaultSSHKeyFile
68
                    ];
69
70
                // If the instance is an array, we get a key => value structure with an Instance key
71
                } elseif (is_array($gerritInstance) && isset($gerritInstance['Instance'])) {
72
                    $instanceConfig = [
73
                        'Instance' => $gerritInstance['Instance'],
74
                        'KeyFile' => $defaultSSHKeyFile
75
                    ];
76
77
                    if (array_key_exists('KeyFile', $gerritInstance) === true) {
78
                        $instanceConfig['KeyFile'] = $gerritInstance['KeyFile'];
79
                    }
80
                } else {
81
                    throw new \RuntimeException('No Gerrit instance config given', 1415451921);
82
                }
83
84
                $dataService = DataServiceFactory::getDataService($instanceConfig);
85
                $projects = $dataService->getProjects();
86
87
                if (is_array($projects) === false) {
88
                    throw new \Exception('No projects found on "' . $path['host'] . '"!', 1363894633);
89
                }
90
91
                if ($i >= 1) {
92
                    $output->writeln('');
93
                }
94
95
                $headline = '<comment>Instance: %s (via %s)</comment>';
96
                $headline = sprintf($headline, $path['host'], $dataService->getName());
97
                $output->writeln($headline);
98
                $output->writeln('<comment>' . str_repeat('=', 40) . '</comment>');
99
100
                foreach ($projects as $name => $project) {
101
                    $message = '<info>%s</info>';
102
                    $message = sprintf($message, $name);
103
                    $output->writeln($message);
104
                }
105
106
                $i++;
107
            }
108
        }
109
    }
110
}