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   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 2 Features 3
Metric Value
wmc 6
c 4
b 2
f 3
lcom 1
cbo 4
dl 0
loc 82
ccs 25
cts 25
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getDisplayName() 0 4 1
A getStats() 0 8 2
A getCombatLevel() 0 16 1
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