Completed
Push — master ( a8c34d...77ee73 )
by Glenn
02:32
created

RolesController::search()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use App\Http\Requests;
7
use Silber\Bouncer\Database\Constraints\Roles;
8
9
class RolesController extends Controller
10
{
11
    /**
12
     * Get the role overview.
13
     *
14
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
15
     */
16
    public function index()
17
    {
18
    	$data['roles'] = Roles::all();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The method all() does not seem to exist on object<Silber\Bouncer\Database\Constraints\Roles>.

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...
19
    	return view('roles.index', $data);
20
    }
21
22
    /**
23
     * Search for a specific role.
24
     *
25
     * @param  Request $request
26
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
27
     */
28
    public function search(Request $request)
29
    {
30
        $term = $request->get('term');
31
        $data['roles'] = Roles::where('name', 'LIKE', "$term")->get();
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The method where() does not seem to exist on object<Silber\Bouncer\Database\Constraints\Roles>.

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...
32
        return view('roles.index', $data);
33
    }
34
35
    /**
36
     * Get a specific role. and display it.
37
     *
38
     * @param  int $id the id off the role in the database.
39
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
40
     */
41
    public function show($id)
42
    {
43
        $data['query'] = Roles::find($id);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The method find() does not seem to exist on object<Silber\Bouncer\Database\Constraints\Roles>.

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...
44
        return view('roles.specific', $data);
45
    }
46
47
    /**
48
     * Store the new role in the database.
49
     *
50
     * @return \Illuminate\Http\RedirectResponse
51
     */
52
    public function store()
53
    {
54
        return redirect(302)->back();
55
    }
56
57
    /**
58
     * Display the form for creating a new role.
59
     *
60
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
61
     */
62
    public function create()
63
    {
64
        return view('roles.create');
65
    }
66
67
    /**
68
     * Get the edit form for the selected role.
69
     * @param  int $id The role id in the database.
70
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
71
     */
72
    public function edit($id)
73
    {
74
        $data['query'] = Roles::find($id);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$data was never initialized. Although not strictly required by PHP, it is generally a good practice to add $data = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
Bug introduced by
The method find() does not seem to exist on object<Silber\Bouncer\Database\Constraints\Roles>.

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...
75
        return view('roles.edit', $data);
76
    }
77
78
    /**
79
     * Update a role in the database.
80
     *
81
     * @return \Illuminate\Http\RedirectResponse
82
     */
83
    public function update()
84
    {
85
        return redirect()->back(302);
86
    }
87
88
    /**
89
     * Destroy a role out off the database.
90
     *
91
     * @param  int $id The id in the database for the role.
92
     * @return \Illuminate\Http\RedirectResponse
93
     */
94
    public function destroy($id)
95
    {
96
        Roles::destroy($id);
0 ignored issues
show
Bug introduced by
The method destroy() does not seem to exist on object<Silber\Bouncer\Database\Constraints\Roles>.

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...
97
        session()->flash('message', 'Role deleted');
98
        return redirect()->back(302);
99
    }
100
}
101