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::findByClass()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 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