Passed
Push — master ( fa19ce...ad6694 )
by Alex
03:36
created

SectionController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 17
dl 0
loc 64
rs 10
c 1
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A subnets() 0 5 1
A update() 0 5 1
A drop() 0 5 1
A index() 0 5 1
A byName() 0 5 1
A __construct() 0 3 1
A show() 0 5 1
A create() 0 5 1
1
<?php
2
3
namespace Axsor\PhpIPAM\Http\Controllers;
4
5
use Axsor\PhpIPAM\Http\Requests\SectionRequest;
6
use Axsor\PhpIPAM\Models\CustomField;
7
use Axsor\PhpIPAM\Models\Section;
8
use Axsor\PhpIPAM\Models\Subnet;
9
10
class SectionController
11
{
12
    protected $request;
13
14
    public function __construct()
15
    {
16
        $this->request = new SectionRequest;
17
    }
18
19
    public function index()
20
    {
21
        $response = $this->request->index();
22
23
        return response_to_collect($response, Section::class);
24
    }
25
26
    public function show($section)
27
    {
28
        $response = $this->request->show($section);
29
30
        return new Section($response['data']);
31
    }
32
33
    public function subnets($section)
34
    {
35
        $response = $this->request->subnets($section);
36
37
        return response_to_collect($response, Subnet::class);
38
    }
39
40
    public function byName(string $section)
41
    {
42
        $response = $this->request->byName($section);
43
44
        return new Section($response['data']);
45
    }
46
47
    // TODO upgrade PhpIPAM from 1.3 to 1.5
48
    //public function customFields()
49
    //{
50
    //    $response = $this->request->customFields();
51
    //
52
    //    return response_to_collect($response, CustomField::class);
53
    //}
54
55
    public function create(array $section)
56
    {
57
        $response = $this->request->create($section);
58
59
        return get_id_or_success_status($response);
60
    }
61
62
    public function update($section, array $newData)
63
    {
64
        $response = $this->request->update($section, $newData);
65
66
        return $response['success'];
67
    }
68
69
    public function drop($section)
70
    {
71
        $response = $this->request->drop($section);
72
73
        return $response['success'];
74
    }
75
}
76