SensorDataController::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 11
ccs 0
cts 7
cp 0
crap 2
rs 9.4285
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
        $this->authorize('index', SensorData::class);
30
        
31
        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...
32
    }
33
34
    /**
35
     * Show the form for creating a new resource.
36
     *
37
     * @return Response
38
     */
39
    public function create()
40
    {
41
        $this->authorize('create', SensorData::class);
42
        
43
        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...
44
    }
45
46
    /**
47
     * Store a newly created resource in storage.
48
     *
49
     * @param Request $request
50
     * @return Response
51
     */
52 View Code Duplication
    public function store(Request $request)
53
    {
54
        $this->authorize('store', SensorData::class);
55
        
56
        request()->validate([
57
            'sensor_id' => 'required|integer|digits_between:1,10|exists:sensors,id',
58
            'value' => 'required|max:190|value_string'
59
        ]);
60
61
        $sensorData = SensorData::create($request->all());
62
63
        return redirect()->route('sensordata.show', $sensorData->id)
0 ignored issues
show
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...
Bug introduced by
$sensorData->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

63
        return redirect()->route('sensordata.show', /** @scrutinizer ignore-type */ $sensorData->id)
Loading history...
64
            ->with('success', 'SensorData created successfully');
65
    }
66
67
    /**
68
     * Display the specified resource.
69
     *
70
     * @param  String  $id
71
     * @return Response
72
     */
73 View Code Duplication
    public function show($id)
74
    {
75
        $this->authorize('show', SensorData::class);
76
        
77
        $sensorData = SensorData::findOrFail($id);
78
        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...
79
    }
80
81
    /**
82
     * Show the form for editing the specified resource.
83
     *
84
     * @param  String  $id
85
     * @return Response
86
     */
87 View Code Duplication
    public function edit($id)
88
    {
89
        $this->authorize('edit', SensorData::class);
90
        
91
        $sensorData = SensorData::findOrFail($id);
92
        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...
93
    }
94
95
    /**
96
     * Update the specified resource in storage.
97
     *
98
     * @param Request $request
99
     * @param  String  $id
100
     * @return Response
101
     */
102
    public function update(Request $request, $id)
103
    {
104
        $this->authorize('update', SensorData::class);
105
        
106
        request()->validate([
107
            'sensor_id' => 'required|integer|digits_between:1,10|exists:sensors,id',
108
            'value' => 'required|max:190|value_string'
109
        ]);
110
        $query = SensorData::findOrFail($id)->update($request->all());
0 ignored issues
show
Unused Code introduced by
The assignment to $query is dead and can be removed.
Loading history...
111
        return redirect()->route('sensordata.show', $id)
0 ignored issues
show
Bug introduced by
$id of type string 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

111
        return redirect()->route('sensordata.show', /** @scrutinizer ignore-type */ $id)
Loading history...
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...
112
            ->with('success', 'SensorData updated successfully');    
113
    }
114
115
    /**
116
     * Remove the specified resource from storage.
117
     *
118
     * @param  String  $id
119
     * @return Response
120
     */
121
    public function destroy($id)
122
    {
123
        $this->authorize('destroy', SensorData::class);
124
        
125
        SensorData::findOrFail($id)->delete();
126
        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...
127
            ->with('success', 'SensorData deleted successfully');
128
    }
129
130
}
131