Tilesets::list()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Bakerkretzmar\LaravelMapbox;
4
5
use RunTimeException;
6
7
use Zttp\Zttp;
8
9
class Tilesets extends MapboxRequest
10
{
11
    /**
12
     * Create a new Tileset request instance.
13
     *
14
     * @param  string|null  $tileset_id
15
     */
16 14
    public function __construct(string $tileset = null)
17
    {
18 14
        $this->tileset = $tileset;
19 14
    }
20
21
    /**
22
     * List Tilesets.
23
     *
24
     * @see     https://docs.mapbox.com/api/maps/#list-tilesets
25
     * @return  array
26
     */
27 14
    public function list()
28
    {
29 14
        return Zttp::get($this->url(Mapbox::TILESETS_ENDPOINT))->json();
30
    }
31
32
    /**
33
     * Delete a Tileset.
34
     *
35
     * @see     https://docs.mapbox.com/api/maps/#delete-tileset
36
     * @return  bool
37
     */
38 8
    public function delete()
39
    {
40 8
        if (! $this->tileset) {
41
            throw new RunTimeException('Tileset name required');
42
        }
43
44 8
        $url = $this->url(Mapbox::TILESETS_ENDPOINT);
45 8
        [$url_before, $url_after] = explode('?', $url);
46 8
        $url = $url_before . '.' . $this->tileset . '?' . $url_after;
47
48 8
        return Zttp::delete($url)->status() === Mapbox::DELETE_SUCCESS_STATUS;
49
    }
50
}
51