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.
Completed
Push — evangelist ( 4d3f68...3fc8d9 )
by Temitope
04:51
created

EvangelistStatus::getGitApiData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 8
Bugs 3 Features 3
Metric Value
c 8
b 3
f 3
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 23 and the first side effect is on line 5.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
namespace Laztopaz\OpenSourceEvangelistStatus;
4
5
error_reporting(0);
6
7
/**
8
 * @package  Laztopaz\OpenSourceEvangelistStatus
9
 * @author   Temitope Olotin <[email protected]>
10
 * @license  <https://opensource.org/license/MIT> MIT
11
 */
12
13
use Dotenv\Dotenv;
14
use GuzzleHttp\Client;
15
use Laztopaz\OpenSourceEvangelistStatus\EvangelistStatusInterface;
16
use Laztopaz\OpenSourceEvangelistStatus\EvangelistStatusRanking;
17
use Laztopaz\OpenSourceEvangelistStatus\EvangelistStatusException;
18
use Laztopaz\OpenSourceEvangelistStatus\NullNoOfReposException;
19
use Laztopaz\OpenSourceEvangelistStatus\ArgumentCheckException;
20
use Exception;
21
22
23
class EvangelistStatus implements EvangelistStatusInterface
24
{
25
    protected  $githubApi;
26
    public     $username;
27
    private    $response;
28
    private    $clientId;
29
    private    $clientSecret;
30
    private    $guzzleClient;
31
    private    $githubResponse;
32
    private    $noOfGitRepos;
33
	
34
    public function __construct($username)
35
    { 
36
        $this->username                         = $username;
37
38
        $num_args = (int) func_num_args(); // get number of arguments passed to 
39
40
        if ($num_args == 0 ||  $num_args > 1) {
41
            throw ArgumentCheckException::NullOfOverflowArgumentException("Argument missing: only one argument is allowed");
42
        }
43
      
44
        $this->username                         = $username;
45
        
46
47
        $this->checkNullUsernameException();
48
49
        $this->clientId                         = getenv('ClientID'); // get the GitHub client id
50
        $this->clientSecret                     = getenv('ClientSecret'); // get the GitHub client secret
51
52
        $this->guzzleClient                     = new Client();
53
54
        $this->githubResponse                   = $this->getGitApiData(); // return GitHub jsonObject
55
        $this->noOfGitRepos                     = $this->getNumberOfRepos(); // return number of repo the user has
56
    }
57
58
    /**
59
     * This method returns Github JSON data 
60
     * @param    void
61
     * @return   response 
62
     */
63
    public function getGitApiData()
64
    {
65
        $this->response = $this->guzzleClient->get('https://api.github.com/users/'.$this->username.'?client_id='.$this->clientId .'&client_secret='.$this->clientSecret);
66
        return $this->response->getBody();
67
    }
68
69
    /**
70
     * This method returns number of the user repo on Github
71
     * @param void
72
     * @return public_repos
73
     */
74
    public function getNumberOfRepos()
75
    {
76
        $githubJson = json_decode($this->githubResponse, true);
77
78
        if (EvangelistStatusRanking::checkForNullRepos($githubJson)) {
79
            throw NullNoOfReposException::createNullReposException("Empty GitHub repository");
80
        }
81
        return $githubJson['public_repos'];
82
    }
83
84
    /**
85
     * This method returns a string depending on number of user repositories on Github
86
     * @param void 
87
     * @return string evangelistRanking
88
     */
89
    public function getStatus()
90
    {
91
        return EvangelistStatusRanking::determineEvangelistLevel($this->noOfGitRepos); 
92
    }
93
94
    /**
95
     * This method checks for empty GitHub username
96
     * @param string $username
97
     * @return boolean
98
     */
99
    public function checkEmptyGithubUsername($username)
100
    {
101
        if ($username == "") {
102
            return true;
103
        }
104
        return false;
105
    }
106
107
    /**
108
     * This method checks for null argument 
109
     * @return exception
110
     */
111
    public function checkNullUsernameException()
112
    {
113
        if ($this->checkEmptyGithubUsername($this->username)) {
114
            throw EvangelistStatusException::createEvangelistStatusException("Username is Empty, please provide a GitHub valid username");
115
        }
116
    }
117
}  
118