Passed
Push — master ( cdfcce...65a138 )
by Alex
06:05
created

ToolController::tags()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Axsor\PhpIPAM\Http\Controllers;
4
5
use Axsor\PhpIPAM\Http\Requests\ToolRequest;
6
use Axsor\PhpIPAM\Models\Location;
7
use Axsor\PhpIPAM\Models\Tag;
8
9
class ToolController
10
{
11
    protected $request;
12
13
    public function __construct()
14
    {
15
        $this->request = new ToolRequest();
16
    }
17
18
    public function locations()
19
    {
20
        $response = $this->request->locations();
21
22
        return response_to_collect($response, Location::class);
23
    }
24
25
    public function location($location)
26
    {
27
        $response = $this->request->location($location);
28
29
        return new Location($response['data']);
30
    }
31
32
    public function locationCreate(array $location)
33
    {
34
        $response = $this->request->locationCreate($location);
35
36
        return get_key_or_null($response, 'id');
37
    }
38
39
    public function locationUpdate($location, array $newData)
40
    {
41
        $response = $this->request->locationUpdate($location, $newData);
42
43
        return (bool) $response['success'];
44
    }
45
46
    public function locationDrop($location)
47
    {
48
        $response = $this->request->locationDrop($location);
49
50
        return (bool) $response['success'];
51
    }
52
53
    public function tags()
54
    {
55
        $response = $this->request->tags();
56
57
        return response_to_collect($response, Tag::class);
58
    }
59
60
    public function tag($tag)
61
    {
62
        $response = $this->request->tag($tag);
63
64
        return new Tag($response['data']);
65
    }
66
67
    public function tagCreate(array $tag)
68
    {
69
        $response = $this->request->tagCreate($tag);
70
71
        return get_key_or_null($response, 'id');
72
    }
73
74
    public function tagUpdate($tag, array $newData)
75
    {
76
        $response = $this->request->tagUpdate($tag, $newData);
77
78
        return (bool) $response['success'];
79
    }
80
81
    public function tagDrop($tag)
82
    {
83
        $response = $this->request->tagDrop($tag);
84
85
        return (bool) $response['success'];
86
    }
87
}
88