1
|
|
|
<?php |
2
|
|
|
namespace Spatie\UptimeMonitor\Http\Controller; |
3
|
|
|
|
4
|
|
|
use App\Http\Controllers\Controller; |
5
|
|
|
use Illuminate\Http\Request; |
6
|
|
|
use Spatie\UptimeMonitor\Models\Monitor; |
7
|
|
|
|
8
|
|
|
class MonitorController extends Controller |
9
|
|
|
{ |
10
|
|
|
/** |
11
|
|
|
* Display a listing of the resource. |
12
|
|
|
* |
13
|
|
|
* @return \Illuminate\Http\Response |
14
|
|
|
*/ |
15
|
|
|
public function index() |
16
|
|
|
{ |
17
|
|
|
return Monitor::all(); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Store a newly created resource in storage. |
22
|
|
|
* |
23
|
|
|
* @param \Illuminate\Http\Request $request |
24
|
|
|
* @return \Illuminate\Http\Response |
25
|
|
|
*/ |
26
|
|
|
public function store(Request $request) |
27
|
|
|
{ |
28
|
|
|
$this->validate($request, config('laravel-uptime-monitor.restAPI.validationRules')); |
29
|
|
|
$url = Url::fromString($request->get('url')); |
30
|
|
|
$monitor = Monitor::create([ |
|
|
|
|
31
|
|
|
'url' => trim($url, '/'), |
32
|
|
|
'look_for_string' => $request->get('look_for_string') ?? '', |
33
|
|
|
'uptime_check_method' => $request->has('look_for_string') ? 'get' : 'head', |
34
|
|
|
'certificate_check_enabled' => $url->getScheme() === 'https', |
35
|
|
|
'uptime_check_interval_in_minutes' => config('laravel-uptime-monitor.uptime_check.run_interval_in_minutes'), |
36
|
|
|
]); |
37
|
|
|
return response()->setStatusCode(201); |
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Display the specified resource. |
42
|
|
|
* |
43
|
|
|
* @param int $id |
44
|
|
|
* @return \Illuminate\Http\Response |
45
|
|
|
*/ |
46
|
|
|
public function show($id) |
47
|
|
|
{ |
48
|
|
|
return Monitor::findOrFail($id); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Update the specified resource in storage. |
53
|
|
|
* |
54
|
|
|
* @param \Illuminate\Http\Request $request |
55
|
|
|
* @param int $id |
56
|
|
|
* @return \Illuminate\Http\Response |
57
|
|
|
*/ |
58
|
|
|
public function update(Request $request, $id) |
59
|
|
|
{ |
60
|
|
|
$this->validate($request, config('laravel-uptime-monitor.restAPI.validationRules')); |
61
|
|
|
|
62
|
|
|
$monitor = Monitor::findOrFail($id); |
63
|
|
|
$look_for_string = ($request->has('look_for_string')) ? $request->get('look_for_string') : $monitor->look_for_string; |
64
|
|
|
return $monitor->update(['url' => $request->get('url'), 'look_for_string' => $look_for_string]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Remove the specified resource from storage. |
69
|
|
|
* |
70
|
|
|
* @param int $id |
71
|
|
|
* @return \Illuminate\Http\Response |
72
|
|
|
*/ |
73
|
|
|
public function destroy($id) |
74
|
|
|
{ |
75
|
|
|
$monitor = Monitor::findOrFail($id); |
76
|
|
|
return $monitor->delete(); |
77
|
|
|
} |
78
|
|
|
} |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
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.