Completed
Pull Request — master (#107)
by Glenn
15:22 queued 07:05
created

TaskController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 2
Metric Value
c 2
b 1
f 2
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\TasksRequest;
6
use Illuminate\Http\Request;
7
use App\Http\Requests;
8
use App\Http\Controllers\Controller;
9
10
use App\User;
11
use App\Tasks;
12
13
/**
14
 * Class TaskController
15
 * @package App\Http\Controllers
16
 */
17
class TaskController extends Controller
18
{
19
    /**
20
     * TaskController constructor.
21
     */ 
22
    public function __construct()
23
    {
24
        $this->middleware('auth');
25
        $this->middleware('lang');
26
    }
27
28
    /**
29
     * Display a listing of the resource.
30
     *
31
     * @return \Illuminate\Http\Response
32
     */
33
    public function index()
34
    {
35
        $data['tasks'] = TasksRequest::paginate(15);
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...
36
        return view("tasks.manage_tasks", $data);
37
    }
38
39
    /**
40
     * Show the form for creating a new resource.
41
     *
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function create()
45
    {
46
        $data['users'] = User::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...
47
        $data['tasks'] = Tasks::all();
48
49
        return view("tasks.request_task", $data);
50
    }
51
52
    /**
53
     * Store a newly created resource in storage.
54
     *
55
     * @param  Requests\taskRequestValidator $request
56
     * @return \Illuminate\Http\Response
57
     */
58
    public function store(Requests\taskRequestValidator $request)
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...
59
    {
60
       //
61
    }
62
63
    /**
64
     * Display the specified resource.
65
     *
66
     * @param  int  $id, The id off the task in the database.
0 ignored issues
show
Bug introduced by
There is no parameter named $id,. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
67
     * @return \Illuminate\Http\Response
68
     */
69
    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...
70
    {
71
        // 
72
    }
73
74
    /**
75
     * Show the form for editing the specified resource.
76
     *
77
     * @param  int $id The id off the task in the database.
78
     * @return \Illuminate\Http\Response
79
     */
80
    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...
81
    {
82
        //
83
    }
84
85
    /**
86
     * Update the specified resource in storage.
87
     *
88
     * @param  Requests\taskValidator $request
89
     * @param  int $id, the task request id.
0 ignored issues
show
Bug introduced by
There is no parameter named $id,. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
90
     * @return \Illuminate\Http\Response
91
     */
92
    public function update(Requests\taskValidator $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...
93
    {
94
        //
95
    }
96
97
    /**
98
     * Remove the specified resource from storage.
99
     *
100
     * @param Request $request
101
     * @return \Illuminate\Http\Response
102
     */
103
    public function destroy(Request $request)
104
    {
105
        TasksRequest::destroy($request->get('integer'));
106
        session()->flash('message', trans('FlashSession.tasksDestroy'));
107
108
        return redirect()->back();
109
    }
110
}
111