Completed
Push — master ( cff7c2...faca46 )
by Tim
04:34 queued 02:07
created

RolesController::search()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 1
Metric Value
c 3
b 1
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
    /**
50
     * Store a new role in the database.
51
     * 
52
     * @return \Illuminate\Http\RedirectResponse
53
     */
54
    public function store()
55
    {
56
        return redirect(302)->back();
57
    }
58
59
    /**
60
     * Display the form for creating a new role.
61
     *
62
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
63
     */
64
    public function create()
65
    {
66
        return view('roles.create');
67
    }
68
69
    /**
70
     * Get the edit form for the selected role.
71
     * @param  int $id The role id in the database.
72
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
73
     */
74
    public function edit($id)
75
    {
76
        $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...
77
        return view('roles.edit', $data);
78
    }
79
80
    /**
81
     * Update a role in the database.
82
     *
83
     * @return \Illuminate\Http\RedirectResponse
84
     */
85
    public function update()
86
    {
87
        return redirect()->back(302);
88
    }
89
90
    /**
91
     * Destroy a role out off the database.
92
     *
93
     * @param  int $id The id in the database for the role.
94
     * @return \Illuminate\Http\RedirectResponse
95
     */
96
    public function destroy($id)
97
    {
98
        Roles::destroy($id);
99
        session()->flash('message', 'Role deleted');
100
        return redirect()->back(302);
101
    }
102
}
103
104