Completed
Push — master ( 9d3bbf...ed7dc7 )
by Glenn
02:43
created

RolesController::search()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
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
8
use App\Roles as Roles;
9
10
class RolesController extends Controller
11
{
12
    /**
13
     * Get the role overview.
14
     *
15
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
16
     */
17
    public function index()
18
    {
19
    	$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...
20
    	return view('roles.index', $data);
21
    }
22
23
    /**
24
     * Search for a specific role.
25
     *
26
     * @param  Request $request
27
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
28
     */
29
    public function search(Request $request)
30
    {
31
        $term = $request->get('term');
32
        $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...
33
        return view('roles.index', $data);
34
    }
35
36
    /**
37
     * Get a specific role. and display it.
38
     *
39
     * @param  int $id the id off the role in the database.
40
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
41
     */
42
    public function show($id)
43
    {
44
        $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...
45
        return view('roles.specific', $data);
46
    }
47
48
    /**
49
     * Store the new role in the database.
50
     *
51
     * @return \Illuminate\Http\RedirectResponse
52
     */
53
    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...
54
    {
55
    	return view('roles.edit');
56
    }
57
58
    public function store()
59
    {
60
        return redirect(302)->back();
61
    }
62
63
    /**
64
     * Display the form for creating a new role.
65
     *
66
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
67
     */
68
    public function create()
69
    {
70
        return view('roles.create');
71
    }
72
73
    /**
74
     * Get the edit form for the selected role.
75
     * @param  int $id The role id in the database.
76
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
77
     */
78
    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...
79
    {
80
        $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...
81
        return view('roles.edit', $data);
82
    }
83
84
    /**
85
     * Update a role in the database.
86
     *
87
     * @return \Illuminate\Http\RedirectResponse
88
     */
89
    public function update()
90
    {
91
        return redirect()->back(302);
92
    }
93
94
    /**
95
     * Destroy a role out off the database.
96
     *
97
     * @param  int $id The id in the database for the role.
98
     * @return \Illuminate\Http\RedirectResponse
99
     */
100
    public function destroy($id)
101
    {
102
        Roles::destroy($id);
103
        session()->flash('message', 'Role deleted');
104
        return redirect()->back(302);
105
    }
106
}
107
108