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.

ProjectRepository   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 121
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 121
ccs 0
cts 45
cp 0
rs 10
c 2
b 1
f 1

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getDataService() 0 4 1
A setDataService() 0 4 1
A getTransformerFactory() 0 4 1
A setTransformerFactory() 0 4 1
B getProjects() 0 46 4
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\API\Repository;
12
13
use Gerrie\API\DataService\DataServiceInterface;
14
use Gerrie\Transformer\TransformerFactory;
15
16
class ProjectRepository
17
{
18
    /**
19
     * API connection
20
     *
21
     * @var DataServiceInterface
22
     */
23
    protected $dataService;
24
25
    /**
26
     * @var TransformerFactory
27
     */
28
    protected $transformerFactory;
29
30
    /**
31
     * @param DataServiceInterface $dataService
32
     * @param TransformerFactory $transformerFactory
33
     */
34
    public function __construct(DataServiceInterface $dataService, TransformerFactory $transformerFactory)
35
    {
36
        $this->setDataService($dataService);
37
        $this->setTransformerFactory($transformerFactory);
38
    }
39
40
    /**
41
     * Returns the data service for API communication
42
     *
43
     * @return DataServiceInterface
44
     */
45
    public function getDataService()
46
    {
47
        return $this->dataService;
48
    }
49
50
    /**
51
     * Sets the data service for API communication
52
     *
53
     * @param DataServiceInterface $dataService
54
     * @return void
55
     */
56
    public function setDataService(DataServiceInterface $dataService)
57
    {
58
        $this->dataService = $dataService;
59
    }
60
61
    /**
62
     * Returns the transformer factory
63
     *
64
     * @return TransformerFactory
65
     */
66
    public function getTransformerFactory()
67
    {
68
        return $this->transformerFactory;
69
    }
70
71
    /**
72
     * Sets the transformer factory
73
     *
74
     * @param TransformerFactory $transformerFactory
75
     * @return void
76
     */
77
    public function setTransformerFactory(TransformerFactory $transformerFactory)
78
    {
79
        $this->transformerFactory = $transformerFactory;
80
    }
81
82
    /**
83
     * Returns all projects by Gerrit API.
84
     * The returned projects are already transformed to a unique format.
85
     *
86
     * @param bool $debuggingEnabled
87
     * @return array
88
     * @throws \RuntimeException
89
     */
90
    public function getProjects($debuggingEnabled = false)
91
    {
92
        $dataService = $this->getDataService();
93
        $projects = $dataService->getProjects();
94
95
        if (is_array($projects) === false) {
96
            $message = 'No projects found on "%s"!';
97
            $message = sprintf($message, $dataService->getHost());
98
            throw new \RuntimeException($message, 1363894633);
99
        }
100
101
        $transformerFactory = $this->getTransformerFactory();
102
        $projectTransformer = $transformerFactory->getTransformer('Project', $debuggingEnabled);
103
104
        $transformedProjects = [];
105
        foreach ($projects as $name => $project) {
106
            if (array_key_exists('_name', $project)) {
107
                /**
108
                 * In "$project" we do not get the name of the project.
109
                 * The array index is the key.
110
                 * We want to transform this name as well, so we add this information with a kind of
111
                 * "reserved" keyword (prefixed with "_").
112
                 * But if this key is already taken (maybe in feature versions) this exception
113
                 * will be thrown and we have to take care about it and apply a change.
114
                 * Maybe get rid of $name, because this information is already in $project?
115
                 * Depends on the context.
116
                 *
117
                 * If you saw this exception during using Gerrie, please
118
                 * * fix the bug described above yourself and make a pull request
119
                 * * or open an issue on the github project that we can take care of this.
120
                 *
121
                 * Thanks.
122
                 */
123
                $exceptionMessage  = 'Key "_name" already exists. Maybe we can get rid of the $name var?';
124
                $exceptionMessage .= 'Please search for this exception and read the comments.';
125
                throw new \RuntimeException($exceptionMessage, 1420132548);
126
            }
127
            $project['_name'] = $name;
128
129
            // Transform data
130
            $projectTransformer->setData($project);
131
            $transformedProjects[$name] = $projectTransformer->transform();
132
        }
133
134
        return $transformedProjects;
135
    }
136
}