Tilesets::delete()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
ccs 6
cts 7
cp 0.8571
crap 2.0116
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