Test Setup Failed
Pull Request — master (#107)
by Tim
61:13 queued 52:59
created

TypesController   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 5
Bugs 1 Features 4
Metric Value
wmc 8
c 5
b 1
f 4
lcom 0
cbo 4
dl 0
loc 97
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A index() 0 5 1
A create() 0 4 1
A store() 0 9 1
A show() 0 4 1
A edit() 0 4 1
A update() 0 4 1
A destroy() 0 8 1
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
        $this->middleware('lang');
20
    }
21
22
    /**
23
     * Display a listing of the resource.
24
     *
25
     * @return \Illuminate\Http\Response
26
     */
27
    public function index()
28
    {
29
        $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...
30
        return view('tasks.manage_types', $data);
31
    }
32
33
    /**
34
     * Show the form for creating a new resource.
35
     *
36
     * @return \Illuminate\Http\Response
37
     */
38
    public function create()
39
    {
40
        //
41
    }
42
43
    /**
44
     * Store a newly created resource in storage.
45
     *
46
     * @param Requests\taskValidator|Request $request
47
     * @return \Illuminate\Http\Response
48
     */
49
    public function store(Requests\taskValidator $request)
50
    {
51
        // Input: name
52
        // Input: Priority.
53
        Tasks::create($request->except('_token'));
54
55
        session()->flash('message', 'The task is successfully added.');
56
        return redirect()->back();
57
    }
58
59
    /**
60
     * Display the specified resource.
61
     *
62
     * @param  int  $id
63
     * @return \Illuminate\Http\Response
64
     */
65
    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...
66
    {
67
        //
68
    }
69
70
    /**
71
     * Show the form for editing the specified resource.
72
     *
73
     * @param  int  $id
74
     * @return \Illuminate\Http\Response
75
     */
76
    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...
77
    {
78
        //
79
    }
80
81
    /**
82
     * Update the specified resource in storage.
83
     *
84
     * @param  \Illuminate\Http\Request  $request
85
     * @param  int  $id
86
     * @return \Illuminate\Http\Response
87
     */
88
    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...
89
    {
90
        //
91
    }
92
93
    /**
94
     * Remove the specified resource from storage.
95
     *
96
     * @param  int  $id
97
     * @return \Illuminate\Http\Response
98
     */
99
    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...
100
    {
101
        $tasks = Tasks::find($id);
102
        $tasks->delete();
103
        session()->flash('message', 'The task is successfully deleted');
104
105
        return redirect()->back();
106
    }
107
}
108