Completed
Pull Request — master (#107)
by Glenn
11:49 queued 05:48
created

TypesController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Tasks;
6
use Illuminate\Http\Request;
7
8
use App\Http\Requests;
9
use App\Http\Controllers\Controller;
10
11
class TypesController extends Controller
12
{
13
    /**
14
     * TypesController constructor.
15
     */ 
16
    public function __construct()
17
    {
18
        $this->middleware('auth');
19
    }
20
21
    /**
22
     * Display a listing of the resource.
23
     *
24
     * @return \Illuminate\Http\Response
25
     */
26
    public function index()
27
    {
28
        $data['tasks'] = Tasks::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...
29
        return view('tasks.manage_types', $data);
30
    }
31
32
    /**
33
     * Show the form for creating a new resource.
34
     *
35
     * @return \Illuminate\Http\Response
36
     */
37
    public function create()
38
    {
39
        //
40
    }
41
42
    /**
43
     * Store a newly created resource in storage.
44
     *
45
     * @param Requests\taskValidator|Request $request
46
     * @return \Illuminate\Http\Response
47
     */
48
    public function store(Requests\taskValidator $request)
49
    {
50
        // Input: name
51
        // Input: Priority.
52
        Tasks::create($request->except('_token'));
53
54
        session()->flash('message', 'The task is successfully added.');
55
        return redirect()->back();
56
    }
57
58
    /**
59
     * Display the specified resource.
60
     *
61
     * @param  int  $id
62
     * @return \Illuminate\Http\Response
63
     */
64
    public function show($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...
65
    {
66
        //
67
    }
68
69
    /**
70
     * Show the form for editing the specified resource.
71
     *
72
     * @param  int  $id
73
     * @return \Illuminate\Http\Response
74
     */
75
    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...
76
    {
77
        //
78
    }
79
80
    /**
81
     * Update the specified resource in storage.
82
     *
83
     * @param  \Illuminate\Http\Request  $request
84
     * @param  int  $id
85
     * @return \Illuminate\Http\Response
86
     */
87
    public function update(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
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...
88
    {
89
        //
90
    }
91
92
    /**
93
     * Remove the specified resource from storage.
94
     *
95
     * @param  int  $id
96
     * @return \Illuminate\Http\Response
97
     */
98
    public function destroy(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request 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...
99
    {
100
        $tasks = Tasks::find($id);
101
        $tasks->delete();
102
        session()->flash('message', 'The task is successfully deleted');
103
104
        return redirect()->back();
105
    }
106
}
107