Completed
Push — TrainingTypePhase2 ( 02e5d6 )
by D.
07:24
created

TrainingTypeController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace SET\Http\Controllers;
4
5
use Illuminate\Http\Request;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Support\Facades\Input;
8
use Krucas\Notification\Facades\Notification;
9
use SET\Http\Controllers\Controller;
10
use SET\Http\Requests\StoreTrainingTypeRequest;
11
use SET\TrainingType;
12
13
class TrainingTypeController extends Controller
14
{
15
    /**
16
     * Display a listing of the resource.
17
     *
18
     * @return \Illuminate\Http\Response
19
     */
20
    public function index()
21
    {
22
        $this->authorize('view');
23
        $trainingtypes = TrainingType::orderBy('name')->get();
24
        return view('trainingtype.index', compact('trainingtypes'));
25
    }
26
27
    /**
28
     * Show the form for creating a new resource.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function create()
33
    {
34
        $this->authorize('edit');
35
        return view('trainingtype.create');
36
    }
37
38
    /**
39
     * Store a newly created resource in storage.
40
     *
41
     * @param  StoreTrainingTypeRequest  $request
42
     * @return \Illuminate\Http\Response
43
     */
44
    public function store(StoreTrainingTypeRequest $request)
45
    {
46
        $trainingtype = TrainingType::create($request->all());
0 ignored issues
show
Unused Code introduced by
$trainingtype is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
47
        Notification::container()->success('Training Type Created');
48
        return redirect()->action('TrainingTypeController@index');
49
    }
50
51
    /**
52
     * Show the individual training type record.
53
     *
54
     * @param $trainingtypeId
55
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
56
     */
57
    public function show($trainingtypeId)
58
    {
59
       $this->authorize('view');
60
       $trainingtype = TrainingType::find($trainingtypeId);
61
       $trainings = $trainingtype->trainings;
62
       return view('trainingtype.show', compact('trainingtype', 'trainings'));
63
    }
64
65
    /**
66
     * Show the form for editing the specified resource.
67
     *
68
     * @param  int  $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...
69
     * @return \Illuminate\Http\Response
70
     */
71
    public function edit(TrainingType $trainingtype)
72
    {
73
        $this->authorize('edit');
74
        return view('trainingtype.edit', compact('trainingtype'));
75
    }
76
77
    /**
78
     * Update the specified resource in storage.
79
     *
80
     * @param  \Illuminate\Http\Request  $request
81
     * @param  int  $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...
82
     * @return \Illuminate\Http\Response
83
     */
84 View Code Duplication
    public function update(StoreTrainingTypeRequest $request, TrainingType $trainingtype)
85
    {
86
       $this->authorize('edit');
87
       $data = $request->all();
88
       $trainingtype->update($data);
89
       Notification::container()->success('Training Type Updated');
90
       return redirect()->action('TrainingTypeController@show', $trainingtype->id);
0 ignored issues
show
Documentation introduced by
The property id does not exist on object<SET\TrainingType>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
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($id)
100
    {
101
        $this->authorize('edit');
102
        $trainingtype = TrainingType::findOrFail($id);
103
        $trainingtype->trainings()->update(['training_type_id'=>null]);
104
        $trainingtype->delete();
105
    }
106
}
107