Completed
Push — master ( 7a6ba1...6f3e87 )
by D.
09:14
created

TrainingTypeController::edit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

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 3
nc 1
nop 1
1
<?php
2
3
namespace SET\Http\Controllers;
4
5
use Krucas\Notification\Facades\Notification;
6
use SET\Http\Requests\StoreTrainingTypeRequest;
7
use SET\TrainingType;
8
9
class TrainingTypeController extends Controller
10
{
11
    /**
12
     * Display a listing of the resource.
13
     *
14
     * @return \Illuminate\Http\Response
15
     */
16
    public function index()
17
    {
18
        $this->authorize('view');
19
        $trainingtypes = TrainingType::orderBy('name')->get();
20
21
        return view('trainingtype.index', compact('trainingtypes'));
22
    }
23
24
    /**
25
     * Show the form for creating a new resource.
26
     *
27
     * @return \Illuminate\Http\Response
28
     */
29
    public function create()
30
    {
31
        $this->authorize('edit');
32
33
        return view('trainingtype.create');
34
    }
35
36
    /**
37
     * Store a newly created resource in storage.
38
     *
39
     * @param StoreTrainingTypeRequest $request
40
     *
41
     * @return \Illuminate\Http\Response
42
     */
43
    public function store(StoreTrainingTypeRequest $request)
44
    {
45
        $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...
46
        Notification::container()->success('Training Type Created');
47
48
        return redirect()->action('TrainingTypeController@index');
49
    }
50
51
    /**
52
     * Show the individual training type record.
53
     *
54
     * @param $trainingtypeId
55
     *
56
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
57
     */
58
    public function show($trainingtypeId)
59
    {
60
        $this->authorize('view');
61
        $trainingtype = TrainingType::find($trainingtypeId);
62
        $trainings = $trainingtype->trainings;
63
64
        return view('trainingtype.show', compact('trainingtype', 'trainings'));
65
    }
66
67
    /**
68
     * Show the form for editing the specified resource.
69
     *
70
     * @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...
71
     *
72
     * @return \Illuminate\Http\Response
73
     */
74
    public function edit(TrainingType $trainingtype)
75
    {
76
        $this->authorize('edit');
77
78
        return view('trainingtype.edit', compact('trainingtype'));
79
    }
80
81
    /**
82
     * Update the specified resource in storage.
83
     *
84
     * @param \Illuminate\Http\Request $request
85
     * @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...
86
     *
87
     * @return \Illuminate\Http\Response
88
     */
89 View Code Duplication
    public function update(StoreTrainingTypeRequest $request, TrainingType $trainingtype)
90
    {
91
        $this->authorize('edit');
92
        $data = $request->all();
93
        $trainingtype->update($data);
94
        Notification::container()->success('Training Type Updated');
95
96
        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...
97
    }
98
99
    /**
100
     * Remove the specified resource from storage.
101
     *
102
     * @param int $id
103
     *
104
     * @return \Illuminate\Http\Response
105
     */
106
    public function destroy($id)
107
    {
108
        $this->authorize('edit');
109
        $trainingtype = TrainingType::findOrFail($id);
110
        $trainingtype->trainings()->update(['training_type_id'=>null]);
111
        $trainingtype->delete();
112
    }
113
}
114