Completed
Pull Request — master (#133)
by
unknown
05:13
created

SensorDataController::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php 
2
3
namespace App\Http\Controllers;
4
5
use App\SensorData;
6
use App\DataTables\SensorDataDataTable;
7
use Illuminate\Http\Request;
8
9
class SensorDataController extends Controller 
10
{
11
    /**
12
     * Create a new controller instance.
13
     *
14
     * @return void
15
     */
16
    public function __construct()
17
    {
18
        $this->middleware('auth');
19
    }
20
21
    /**
22
     * Display a listing of the resource.
23
     *
24
     * @param SensorDataDataTable $dataTable
25
     * @return Response
0 ignored issues
show
Bug introduced by
The type App\Http\Controllers\Response was not found. Did you mean Response? If so, make sure to prefix the type with \.
Loading history...
26
     */
27
    public function index(SensorDataDataTable $dataTable)
28
    {
29
        return $dataTable->render('sensordata.index');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $dataTable->render('sensordata.index') also could return the type Illuminate\View\View|callable which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
30
    }
31
32
    /**
33
     * Show the form for creating a new resource.
34
     *
35
     * @return Response
36
     */
37
    public function create()
38
    {
39
        return view('sensordata.create');
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('sensordata.create') returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
40
    }
41
42
    /**
43
     * Store a newly created resource in storage.
44
     *
45
     * @param Request $request
46
     * @return Response
47
     */
48 View Code Duplication
    public function store(Request $request)
49
    {
50
        request()->validate([
51
            'sensor_id' => 'required|integer|digits_between:1,10|exists:sensors,id',
52
            'value' => 'required|max:190|value_string'
53
        ]);
54
55
        $query = SensorData::create($request->all());
56
57
        return redirect()->route('sensordata.show', $query->id)
0 ignored issues
show
Bug introduced by
$query->id of type integer is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        return redirect()->route('sensordata.show', /** @scrutinizer ignore-type */ $query->id)
Loading history...
Bug Best Practice introduced by
The expression return redirect()->route... created successfully') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
58
            ->with('success', 'SensorData created successfully');
59
    }
60
61
    /**
62
     * Display the specified resource.
63
     *
64
     * @param  Request  $request
65
     * @param  int  $id
66
     * @return Response
67
     */
68
    public function show(Request $request, $id)
0 ignored issues
show
Unused Code introduced by
The parameter $request is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

68
    public function show(/** @scrutinizer ignore-unused */ Request $request, $id)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
69
    {
70
        $sensordata = SensorData::findOrFail($id);
71
72
        return view('sensordata.show', [ 'sensordata' => $sensordata ]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('sensordata....rdata' => $sensordata)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
73
    }
74
75
    /**
76
     * Show the form for editing the specified resource.
77
     *
78
     * @param  int  $id
79
     * @return Response
80
     */
81
    public function edit(Request $request, $id)
82
    {
83
        $sensordata = SensorData::findOrFail($id);
84
        
85
        return view('sensordata.edit', [ 'sensordata' => $sensordata ]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return view('sensordata....rdata' => $sensordata)) returns the type Illuminate\View\View which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
86
    }
87
88
    /**
89
     * Update the specified resource in storage.
90
     *
91
     * @param  int  $id
92
     * @return Response
93
     */
94
    public function update($id)
95
    {
96
        request()->validate([
97
            'sensor_id' => 'required|integer|digits_between:1,10|exists:sensors,id',
98
            'value' => 'required|max:190|value_string'
99
        ]);
100
        $query = SensorData::findOrFail($id)->update($request->all());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $request seems to be never defined.
Loading history...
Unused Code introduced by
The assignment to $query is dead and can be removed.
Loading history...
101
        return redirect()->route('sensordata.show', $id)
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route... updated successfully') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
Bug introduced by
$id of type integer is incompatible with the type array expected by parameter $parameters of Illuminate\Routing\Redirector::route(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

101
        return redirect()->route('sensordata.show', /** @scrutinizer ignore-type */ $id)
Loading history...
102
            ->with('success', 'SensorData updated successfully');    
103
    }
104
105
    /**
106
     * Remove the specified resource from storage.
107
     *
108
     * @param  int  $id
109
     * @return Response
110
     */
111
    public function destroy($id)
112
    {
113
        SensorData::find($id)->delete();
114
        return redirect()->route('sensordata.index')
0 ignored issues
show
Bug Best Practice introduced by
The expression return redirect()->route... deleted successfully') returns the type Illuminate\Http\RedirectResponse which is incompatible with the documented return type App\Http\Controllers\Response.
Loading history...
115
            ->with('success', 'SensorData deleted successfully');
116
    }
117
118
}
119