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

Repository   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 80%

Importance

Changes 3
Bugs 1 Features 2
Metric Value
wmc 5
c 3
b 1
f 2
lcom 1
cbo 5
dl 0
loc 77
ccs 24
cts 30
cp 0.8
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A find() 0 6 1
A findByName() 0 6 1
B factory() 0 29 2
A findByClass() 0 6 1
1
<?php
2
3
namespace Burthorpe\Runescape\RS3\Stats;
4
5
use Burthorpe\Runescape\RS3\Skills\Repository as SkillsRepository;
6
use Illuminate\Support\Collection;
7
8
class Repository extends Collection
9
{
10
    /**
11
     * Creates an \Burthorpe\Runescape\RS3\Stats\Repository instance from a raw feed directly from Jagex
12
     *
13
     * @param $rawFeed string Raw feed directly from Jagex
14
     * @return \Burthorpe\Runescape\RS3\Stats\Repository
15
     */
16 4
    public static function factory($rawFeed)
17
    {
18 4
        $repository = new static;
19 4
        $skills     = new SkillsRepository();
20
21 4
        $exploded = explode("\n", $rawFeed);
22
23 4
        $spliced = array_splice(
24 4
            $exploded,
25 4
            0,
26 4
            $skills->count()
27 4
        );
28
29 4
        for ($id = 0; $id < count($spliced); $id++) {
30 4
            list($rank, $level, $experience) = explode(',', $spliced[$id]);
31 4
            $skill                           = $skills->find($id);
32
33 4
            $repository->push(
34 4
                new Stat(
35 4
                    $skill,
36 4
                    $level,
37 4
                    $rank,
38
                    $experience
39 4
                )
40 4
            );
41 4
        }
42
43 4
        return $repository;
44
    }
45
46
    /**
47
     * Find a stat by the given skill ID
48
     *
49
     * @param $id
50
     * @return \Burthorpe\Runescape\RS3\Stats\Contract|null
51
     */
52
    public function find($id)
53
    {
54
        return $this->filter(function (Contract $stat) use ($id) {
55
            return $stat->getSkill()->getId() === $id;
56
        })->first();
57
    }
58
59
    /**
60
     * Find a stat by the given skill name
61
     *
62
     * @param $name
63
     * @return \Burthorpe\Runescape\RS3\Stats\Contract|null
64
     */
65
    public function findByName($name)
66
    {
67
        return $this->filter(function (Contract $stat) use ($name) {
68
            return $stat->getSkill()->getName() === $name;
69
        })->first();
70
    }
71
72
    /**
73
     * Find a stat by the given skill class
74
     *
75
     * @param $class
76
     * @return \Burthorpe\Runescape\RS3\Stats\Contract|null
77
     */
78
    public function findByClass($class)
79
    {
80 1
        return $this->filter(function (Contract $stat) use ($class) {
81 1
            return $stat->getSkill() instanceof $class;
82 1
        })->first();
83
    }
84
}
85