Passed
Push — master ( 396363...2462db )
by Alex
05:04 queued 01:36
created

DeviceController::show()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Axsor\PhpIPAM\Http\Controllers;
4
5
use Axsor\PhpIPAM\Http\Requests\DeviceRequest;
6
use Axsor\PhpIPAM\Models\Device;
7
use Axsor\PhpIPAM\Models\CustomField;
8
use Axsor\PhpIPAM\Models\Section;
9
use Axsor\PhpIPAM\Models\Subnet;
10
use Axsor\PhpIPAM\Models\Address;
11
use Axsor\PhpIPAM\Models\Location;
12
use Axsor\PhpIPAM\Models\Circuit;
13
14
class DeviceController
15
{
16
    protected $request;
17
18
    public function __construct()
19
    {
20
        $this->request = new DeviceRequest;
21
    }
22
23
    public function index()
24
    {
25
        $response = $this->request->index();
26
27
        return response_to_collect($response, Device::class);
28
    }
29
30
    public function show($device)
31
    {
32
        $response = $this->request->show($device);
33
34
        return new Device($response['data']);
35
    }
36
37
    public function types($device)
0 ignored issues
show
Unused Code introduced by
The parameter $device is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

37
    public function types(/** @scrutinizer ignore-unused */ $device)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        $response = $this->request->types();
0 ignored issues
show
Bug introduced by
The method types() does not exist on Axsor\PhpIPAM\Http\Requests\DeviceRequest. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
        /** @scrutinizer ignore-call */ 
40
        $response = $this->request->types();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
41
        return response_to_collect($response, Device::class);
42
    }
43
44
    public function subnets($device)
45
    {
46
        $response = $this->request->subnets($device);
47
48
        return response_to_collect($response, Subnet::class);
49
    }
50
51
    public function addresses($device)
52
    {
53
        $response = $this->request->addresses($device);
54
55
        return response_to_collect($response, Address::class);
56
    }
57
58
    public function create(array $device)
59
    {
60
        $response = $this->request->create($device);
61
62
        return get_key_or_null($response, 'id');
63
    }
64
65
    public function update($device, array $newData)
66
    {
67
        $response = $this->request->update($device, $newData);
68
69
        return (bool) $response['success'];
70
    }
71
72
    public function drop($device)
73
    {
74
        $response = $this->request->drop($device);
75
76
        return (bool) $response['success'];
77
    }
78
}
79