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

Player::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 1
Metric Value
c 2
b 1
f 1
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Burthorpe\Runescape\RS3;
4
5
use Burthorpe\Exception\InvalidDisplayNameException;
6
use Burthorpe\Runescape\Common;
7
use Burthorpe\Runescape\RS3\Skills\Attack;
8
use Burthorpe\Runescape\RS3\Skills\Constitution;
9
use Burthorpe\Runescape\RS3\Skills\Defence;
10
use Burthorpe\Runescape\RS3\Skills\Magic;
11
use Burthorpe\Runescape\RS3\Skills\Prayer;
12
use Burthorpe\Runescape\RS3\Skills\Ranged;
13
use Burthorpe\Runescape\RS3\Skills\Strength;
14
use Burthorpe\Runescape\RS3\Skills\Summoning;
15
use InvalidArgumentException;
16
17
class Player
18
{
19
    /**
20
     * @var \Burthorpe\Runescape\Common
21
     */
22
    protected $common;
23
24
    /**
25
     * @var \Burthorpe\Runescape\RS3\API
26
     */
27
    protected $api;
28
29
    /**
30
     * Players display name
31
     *
32
     * @var string
33
     */
34
    protected $displayName;
35
36
    /**
37
     * @var array
38
     */
39
    protected $stats;
40
41
    /**
42
     * @param $displayName string Runescape display name
43
     * @throws InvalidArgumentException
44
     */
45 6
    public function __construct($displayName)
46
    {
47 6
        $this->common = new Common();
48 6
        $this->api    = new API();
49
50 6
        if ($this->common->validateDisplayName($displayName) === false) {
51 2
            throw new InvalidDisplayNameException();
52
        }
53
54 4
        $this->displayName = $displayName;
55 4
    }
56
57
    /**
58
     * Return the players stats
59
     *
60
     * @return \Burthorpe\Runescape\RS3\Stats\Repository
61
     */
62 2
    public function getStats()
63
    {
64 2
        if ($this->stats) {
65 1
            return $this->stats;
66
        }
67
68 2
        return $this->stats = $this->api->stats($this->getDisplayName());
69
    }
70
71
    /**
72
     * Return the calculated combat level of this player
73
     *
74
     * @param  bool $float
75
     * @return int
76
     */
77 1
    public function getCombatLevel($float = false)
78
    {
79 1
        $stats = $this->getStats();
80
81 1
        return $this->api->calculateCombatLevel(
82 1
            $stats->findByClass(Attack::class)->getLevel(),
83 1
            $stats->findByClass(Strength::class)->getLevel(),
84 1
            $stats->findByClass(Magic::class)->getLevel(),
85 1
            $stats->findByClass(Ranged::class)->getLevel(),
86 1
            $stats->findByClass(Defence::class)->getLevel(),
87 1
            $stats->findByClass(Constitution::class)->getLevel(),
88 1
            $stats->findByClass(Prayer::class)->getLevel(),
89 1
            $stats->findByClass(Summoning::class)->getLevel(),
90
            $float
91 1
        );
92
    }
93
94 3
    public function getDisplayName()
95
    {
96 3
        return $this->displayName;
97
    }
98
}
99