HousesResource::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 3
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