HousesResource   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 10 2
A isAvailableType() 0 4 1
A getAvailableTypes() 0 4 1
1
<?php
2
3
namespace Igorsgm\TibiaDataApi\Resources;
4
5
use Igorsgm\TibiaDataApi\Response\HousesResponse;
6
7
/**
8
 * @see https://tibiadata.com/doc-api-v2/houses/
9
 */
10
class HousesResource extends AbstractResource
11
{
12
    const TYPE_HOUSES = 'houses';
13
14
    const TYPE_GUILDHALLS = 'guildhalls';
15
16
    /**
17
     * @param $world
18
     * @param  string  $town
19
     * @param  string  $type
20
     * @return HousesResponse
21
     * @throws \GuzzleHttp\Exception\GuzzleException
22
     * @throws \Igorsgm\TibiaDataApi\Exceptions\NotFoundException
23
     * @throws \Igorsgm\TibiaDataApi\Exceptions\ImmutableException
24
     */
25
    public function get($world, $town = 'Ab\'Dendriel', $type = self::TYPE_HOUSES)
26
    {
27
        if (!self::isAvailableType($type)) {
28
            throw new \InvalidArgumentException('Invalid type.');
29
        }
30
31
        $response = $this->sendRequest('GET', "houses/{$world}/{$town}/{$type}.json");
32
33
        return new HousesResponse($response);
34
    }
35
36
    /**
37
     * @param  string  $type
38
     * @return bool
39
     */
40
    public static function isAvailableType(string $type): bool
41
    {
42
        return in_array($type, self::getAvailableTypes());
43
    }
44
45
    /**
46
     * @return string[]
47
     */
48
    public static function getAvailableTypes(): array
49
    {
50
        return [self::TYPE_HOUSES, self::TYPE_GUILDHALLS];
51
    }
52
}
53