ToolController   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 25
c 1
b 0
f 0
dl 0
loc 84
rs 10
wmc 12

12 Methods

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