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.

APIConnectionCheck   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 83
ccs 22
cts 22
cp 1
rs 10
c 2
b 0
f 2

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A check() 0 18 3
A getSuccessMessage() 0 7 1
A getFailureMessage() 0 8 1
A isOptional() 0 4 1
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\Check;
12
13
use Gerrie\API\DataService\DataServiceInterface;
14
15
/**
16
 * Checks if the API connection via SSH or REST works as expected.
17
 *
18
 * @author Andreas Grunwald <[email protected]>
19
 */
20
class APIConnectionCheck implements CheckInterface
21
{
22
23
    /**
24
     * DataService object
25
     *
26
     * @var DataServiceInterface
27
     */
28
    protected $dataService;
29
30
    /**
31
     * Version of Gerrit instance
32
     *
33
     * @var string
34
     */
35
    protected $version;
36
37 5
    public function __construct(DataServiceInterface $dataService)
38
    {
39 5
        $this->dataService = $dataService;
40 5
    }
41
42
    /**
43
     * Executes the check itselfs
44
     *
45
     * @return boolean
46
     */
47 2
    public function check()
48
    {
49 2
        $result = false;
50
51 2
        $version = $this->dataService->getVersion();
52
53
        // Check the version. If this is > 0 then it seems to be a version number like 1.2.3
54
        // Because the getVersion method can return an error like
55
        //      Warning: Identity file /Users/agrunwald/.ssh/id_rsa_config not accessible: No such file or directory.
56
        //      Permission denied (publickey).
57
        //
58 2
        if ($version && version_compare($version, 0, '>')) {
59 1
            $this->version = $version;
60 1
            $result = true;
61 1
        }
62
63 2
        return $result;
64
    }
65
66
    /**
67
     * Returns the message, if the check succeeded
68
     *
69
     * @return string
70
     */
71 1
    public function getSuccessMessage()
72
    {
73 1
        $message = 'Connection to Gerrit "%s" (v%s) via %s-DataService was successful and works as expected.';
74 1
        $message = sprintf($message, $this->dataService->getHost(), $this->version, $this->dataService->getName());
75
76 1
        return $message;
77
    }
78
79
    /**
80
     * Returns the message, if the check fails
81
     *
82
     * @return string
83
     */
84 1
    public function getFailureMessage()
85
    {
86 1
        $message  = 'Connection to Gerrit "%s" via %s-DataService was not successful. ';
87 1
        $message .= 'Please check your credentials or setup.';
88 1
        $message = sprintf($message, $this->dataService->getHost(), $this->dataService->getName());
89
90 1
        return $message;
91
    }
92
93
    /**
94
     * Returns if this check is optional or required.
95
     *
96
     * @return bool
97
     */
98 1
    public function isOptional()
99
    {
100 1
        return false;
101
    }
102
}
103