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 — master ( 24594f...2f1bd4 )
by Wade
03:06
created

API::stats()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 10
Bugs 4 Features 2
Metric Value
c 10
b 4
f 2
dl 0
loc 12
ccs 6
cts 6
cp 1
rs 9.4285
cc 2
eloc 7
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Burthorpe\Runescape\RS3;
4
5
use Burthorpe\Exception\UnknownPlayerException;
6
use Burthorpe\Runescape\RS3\Skills\Repository as SkillsRepository;
7
use Burthorpe\Runescape\RS3\Stats\Repository as StatsRepository;
8
use GuzzleHttp\Client as Guzzle;
9
use GuzzleHttp\Exception\RequestException;
10
use GuzzleHttp\Psr7\Request;
11
12
class API
13
{
14
    /**
15
     * @var \Burthorpe\Runescape\RS3\Skills\Repository
16
     */
17
    protected $skills;
18
19
    /**
20
     * Guzzle HTTP client for making requests
21
     *
22
     * @var \GuzzleHttp\Client
23
     */
24
    protected $guzzle;
25
26
    /**
27
     * Array of resource URLs
28
     *
29
     * @var array
30
     */
31
    protected $endpoints = [
32
        'hiscores' => 'http://hiscore.runescape.com/index_lite.ws?player=%s',
33
    ];
34
35
    /**
36
     * Class constructor
37
     */
38 11
    public function __construct()
39 1
    {
40 11
        $this->skills = new SkillsRepository();
41
42 11
        $this->guzzle = new Guzzle([
43
            'headers' => [
44 11
                'User-Agent' => 'Burthorpe Runescape API',
45 11
            ],
46 11
        ]);
47 11
    }
48
49
    /**
50
     * Get a players statistics from the hiscores API feed
51
     *
52
     * @return \Burthorpe\Runescape\RS3\Stats\Repository|bool
53
     *
54
     * @throws \Burthorpe\Exception\UnknownPlayerException
55
     */
56 5
    public function stats($rsn)
57
    {
58 5
        $request = new Request('GET', sprintf($this->endpoints['hiscores'], $rsn));
59
60
        try {
61 5
            $response = $this->guzzle->send($request);
62 5
        } catch (RequestException $e) {
63 1
            throw new UnknownPlayerException($rsn);
64
        }
65
66 4
        return StatsRepository::factory($response->getBody());
67
    }
68
69
    /**
70
     * Get access to the skills helper
71
     *
72
     * @return \Burthorpe\Runescape\RS3\Skills\Repository
73
     */
74 1
    public function getSkills()
75
    {
76 1
        return $this->skills;
77
    }
78
79
    /**
80
     * Calculates a players combat level
81
     *
82
     * @param  int  $attack
83
     * @param  int  $strength
84
     * @param  int  $magic
85
     * @param  int  $ranged
86
     * @param  int  $defence
87
     * @param  int  $constitution
88
     * @param  int  $prayer
89
     * @param  int  $summoning
90
     * @param  bool $float
91
     * @return int
92
     */
93 2
    public function calculateCombatLevel($attack, $strength, $magic, $ranged, $defence, $constitution, $prayer, $summoning, $float = false)
94
    {
95 2
        $highest = max(($attack + $strength), (2 * $magic), (2 * $ranged));
96
97 2
        $cmb = floor(0.25 * ((1.3 * $highest) + $defence + $constitution + floor(0.5 * $prayer) + floor(0.5 * $summoning)));
98
99 2
        return $float ? $cmb : (int) $cmb;
100
    }
101
}
102