Completed
Pull Request — develop (#119)
by Neil
03:08
created

ResourceController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * app/Api/Controllers/General/ResourceController.php
4
 *
5
 * API Controller for resources such as IP, ARP, Mac, etc
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 * @package    LibreNMS
21
 * @link       http://librenms.org
22
 * @copyright  2016 Neil Lathwood
23
 * @author     Neil Lathwood <[email protected]>
24
 */
25
26
namespace App\Api\Controllers\General;
27
28
use App\Api\Controllers\Controller;
29
use App\Models\General\IPv4;
30
use App\Models\General\IPv4Mac;
31
use App\Models\General\IPv6;
32
use App\Models\Port;
33
use Dingo\Api\Http;
34
use Dingo\Api\Routing\Helpers;
35
use Illuminate\Http\Request;
36
37
class ResourceController extends Controller
38
{
39
40
    use Helpers;
41
42
    /**
43
     * Display a listing of all alerts
44
     *
45
     * @param  \Illuminate\Http\Request  $request
46
     * @return \Illuminate\Http\Response
47
     */
48
    public function index(Request $request)
49
    {
50
        return $this->response->array(array('statusText' => 'OK', 'resources' => ['ipv4', 'ipv6', 'arp', 'mac']));
51
    }
52
53
54
    /**
55
     * Show the form for creating a new resource.
56
     *
57
     * @return \Illuminate\Http\Response|null
58
     */
59
    public function create()
60
    {
61
        //
62
    }
63
64
    /**
65
     * Store a newly created resource in storage.
66
     *
67
     * @param  \Illuminate\Http\Request  $request
68
     * @return \Illuminate\Http\Response|null
69
     */
70
    public function store(Request $request)
71
    {
72
        //
73
    }
74
75
    /**
76
     * Display the specified resource.
77
     *
78
     * @param Request $request
0 ignored issues
show
Bug introduced by
There is no parameter named $request. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
79
     * @param string $resource
0 ignored issues
show
Bug introduced by
There is no parameter named $resource. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
80
     * @return \Illuminate\Http\Response|null
81
     */
82
    public function show()
83
    {
84
        //
85
    }
86
87
    /**
88
     * Show the form for editing the specified resource.
89
     *
90
     * @param  int  $id
91
     * @return \Illuminate\Http\Response|null
92
     */
93
    public function edit($id)
1 ignored issue
show
Unused Code introduced by
The parameter $id is not used and could be removed.

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

Loading history...
94
    {
95
        //
96
    }
97
98
    /**
99
     * Update the specified resource in storage.
100
     *
101
     * @param  \Illuminate\Http\Request  $request
102
     * @param  int  $id
103
     * @return \Illuminate\Http\Response|null
104
     */
105
    public function update(Request $request, $id)
1 ignored issue
show
Unused Code introduced by
The parameter $id is not used and could be removed.

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

Loading history...
106
    {
107
        //
108
    }
109
110
    /**
111
     * Remove the specified resource from storage.
112
     *
113
     * @param  int  $id
114
     * @return \Illuminate\Http\Response|null
115
     */
116
    public function destroy($id)
1 ignored issue
show
Unused Code introduced by
The parameter $id is not used and could be removed.

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

Loading history...
117
    {
118
        //
119
    }
120
121
    /**
122
     * Display the specified resource.
123
     *
124
     * @param  \Illuminate\Http\Request  $request
125
     * @return \Illuminate\Pagination\LengthAwarePaginator
126
     */
127
    public function ipv4(Request $request)
128
    {
129
        $per_page = $request->per_page ?: 25;
130
        return IPv4::paginate($per_page);
131
    }
132
133
    /**
134
     * Display the specified resource.
135
     *
136
     * @param  \Illuminate\Http\Request  $request
137
     * @return \Illuminate\Pagination\LengthAwarePaginator
138
     */
139
    public function ipv6(Request $request)
140
    {
141
        $per_page = $request->per_page ?: 25;
142
        return IPv6::paginate($per_page);
143
    }
144
145
    /**
146
     * Display the specified resource.
147
     *
148
     * @param  \Illuminate\Http\Request  $request
149
     * @return \Illuminate\Pagination\LengthAwarePaginator
150
     */
151
    public function mac(Request $request)
152
    {
153
        $per_page = $request->per_page ?: 25;
154
        return Port::select('port_id', 'ifPhysAddress')->paginate($per_page);
155
    }
156
157
    /**
158
     * Display the specified resource.
159
     *
160
     * @param  \Illuminate\Http\Request  $request
161
     * @return \Illuminate\Pagination\LengthAwarePaginator
162
     */
163
    public function arp(Request $request)
164
    {
165
        $per_page = $request->per_page ?: 25;
166
        return IPv4Mac::paginate($per_page);
167
    }
168
169
}
170