Completed
Push — master ( 159a0d...3184f1 )
by Christopher
18:11
created

GithubApi::getStreamContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 3
Bugs 3 Features 1
Metric Value
c 3
b 3
f 1
dl 0
loc 12
ccs 4
cts 4
cp 1
rs 9.4286
cc 1
eloc 5
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 *  @author chris.vundi
4
 *  This class makes a call to Github and returns
5
 *  the number of repos one owns provided a username
6
 *  is provided.
7
 */
8
namespace Vundi\Checkpoint1;
9
use GuzzleHttp\Client;
10
11
class GithubApi
12
{
13
    /**
14
     * Github username
15
     * @var string
16
     */
17
    protected $username;
18
19 3
    public function __construct($username)
20
    {
21 3
        $this->username = $username;
22 3
    }
23
24
    /**
25
     * Get username passed as the parameter
26
     * @return string
27
     */
28 1
    public function getUsername()
29
    {
30 1
        return $this->username;
31
    }
32
33
    /**
34
     * Return an integer representing number of public repos
35
     * the username provided has on github
36
     * @return int
37
     */
38 1
    public function getRepos()
39
    {
40 1
        $url = "https://api.github.com/users/{$this->username}/repos";
41 1
        $client = new Client();
42
        //will return http response with the body in json format
43 1
        $res = $client->request('GET', $url);
44 1
        $decoded = json_decode($res->getBody(), true);
45 1
        $number = count($decoded);
46 1
        return $number;
47
    }
48
49
}
50