Completed
Push — fixes ( 6830e4...798510 )
by Tony
03:34
created

AlertsController::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
/**
3
 * app/Api/Controllers/Alerting/AlertsController.php
4
 *
5
 * API Controller for alerts data
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\Alerting;
27
28
use App\Api\Controllers\Controller;
29
use App\Models\Alerting\Alert;
30
use Dingo\Api\Http;
31
use Dingo\Api\Routing\Helpers;
32
use Illuminate\Http\Request;
33
34
class AlertsController extends Controller
35
{
36
37
    use Helpers;
38
39
    /**
40
     * Display a listing of all alerts
41
     *
42
     * @param Request $request
43
     * @return \Illuminate\Http\Response
44
     */
45
    public function index(Request $request)
46
    {
47
        $per_page = $request->per_page ?: 25;
48
        return Alert::active()->paginate($per_page);
0 ignored issues
show
Bug introduced by
The method paginate does only exist in Illuminate\Database\Query\Builder, but not in App\Models\Alerting\Alert.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
49
    }
50
51
52
    /**
53
     * Show the form for creating a new resource.
54
     *
55
     * @return \Illuminate\Http\Response|null
56
     */
57
    public function create()
58
    {
59
        //
60
    }
61
62
    /**
63
     * Store a newly created resource in storage.
64
     *
65
     * @param  \Illuminate\Http\Request  $request
66
     * @return \Illuminate\Http\Response|null
67
     */
68
    public function store(Request $request)
69
    {
70
        //
71
    }
72
73
    /**
74
     * Display the specified resource.
75
     *
76
     * @param  int  $id
77
     * @return \Illuminate\Http\Response|null
78
     */
79
    public function show(Request $request, $id)
0 ignored issues
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...
80
    {
81
        //
82
    }
83
84
    /**
85
     * Show the form for editing the specified resource.
86
     *
87
     * @param  int  $id
88
     * @return \Illuminate\Http\Response|null
89
     */
90
    public function edit($id)
0 ignored issues
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...
91
    {
92
        //
93
    }
94
95
    public function update(Request $request, $id)
96
    {
97
        $alert         = Alert::find($id);
98
        $alert->state  = $request->input('state');
99 View Code Duplication
        if ($alert->save())
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
100
        {
101
            return $this->response->array(array('statusText' => 'OK'));
102
        }
103
        else {
104
            return $this->response->errorInternal();
105
        }
106
    }
107
108
    /**
109
     * Remove the specified resource from storage.
110
     *
111
     * @param  int  $id
112
     * @return \Illuminate\Http\Response|null
113
     */
114
    public function destroy($id)
0 ignored issues
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...
115
    {
116
        //
117
    }
118
119
}
120