HighscoresResource   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 82
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 10 3
A isAvailableType() 0 4 1
A isAvailableVocation() 0 4 1
A getAvailableTypes() 0 8 1
A getAvailableVocations() 0 6 1
1
<?php
2
3
namespace Igorsgm\TibiaDataApi\Resources;
4
5
use Igorsgm\TibiaDataApi\Response\HighscoresResponse;
6
7
/**
8
 * @see https://tibiadata.com/doc-api-v2/highscores/
9
 */
10
class HighscoresResource extends AbstractResource
11
{
12
13
    const TYPE_EXPERIENCE = 'experience';
14
    const TYPE_MAGIC_LEVEL = 'magic';
15
    const TYPE_SHIELDING = 'shielding';
16
    const TYPE_DISTANCE = 'distance';
17
    const TYPE_SWORD = 'sword';
18
    const TYPE_CLUB = 'club';
19
    const TYPE_AXE = 'axe';
20
    const TYPE_FIST = 'fist';
21
    const TYPE_FISHING = 'fishing';
22
    const TYPE_ACHIEVEMENTS = 'achievements';
23
    const TYPE_LOYALTY = 'loyalty';
24
25
    const VOC_ALL = 'all';
26
    const VOC_NONE = 'no';
27
    const VOC_DRUID = 'druid';
28
    const VOC_KNIGHT = 'knight';
29
    const VOC_PALADIN = 'paladin';
30
    const VOC_SORCERER = 'sorcerer';
31
32
    /**
33
     * @param $server
34
     * @param  string  $type
35
     * @param  string  $vocation
36
     * @return HighscoresResponse
37
     * @throws \GuzzleHttp\Exception\GuzzleException
38
     * @throws \Igorsgm\TibiaDataApi\Exceptions\NotFoundException
39
     * @throws \Igorsgm\TibiaDataApi\Exceptions\ImmutableException
40
     */
41
    public function get($server, string $type = self::TYPE_EXPERIENCE, string $vocation = self::VOC_ALL)
42
    {
43
        if (!self::isAvailableType($type) || !self::isAvailableVocation($vocation)) {
44
            throw new \InvalidArgumentException('Invalid type or vocation.');
45
        }
46
47
        $response = $this->sendRequest('GET', "highscores/{$server}/{$type}/{$vocation}.json");
48
49
        return new HighscoresResponse($response);
50
    }
51
52
    /**
53
     * @param  string  $type
54
     * @return bool
55
     */
56
    public static function isAvailableType(string $type): bool
57
    {
58
        return in_array($type, self::getAvailableTypes());
59
    }
60
61
    /**
62
     * @param  string  $vocation
63
     * @return bool
64
     */
65
    public static function isAvailableVocation(string $vocation): bool
66
    {
67
        return in_array($vocation, self::getAvailableVocations());
68
    }
69
70
    /**
71
     * @return string[]
72
     */
73
    public static function getAvailableTypes(): array
74
    {
75
        return [
76
            self::TYPE_EXPERIENCE, self::TYPE_MAGIC_LEVEL, self::TYPE_SHIELDING, self::TYPE_DISTANCE,
77
            self::TYPE_SWORD, self::TYPE_CLUB, self::TYPE_AXE, self::TYPE_FIST, self::TYPE_FISHING,
78
            self::TYPE_ACHIEVEMENTS, self::TYPE_LOYALTY,
79
        ];
80
    }
81
82
    /**
83
     * @return string[]
84
     */
85
    public static function getAvailableVocations(): array
86
    {
87
        return [
88
            self::VOC_ALL, self::VOC_NONE, self::VOC_DRUID, self::VOC_KNIGHT, self::VOC_PALADIN, self::VOC_SORCERER,
89
        ];
90
    }
91
}
92