GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#47)
by
unknown
02:00
created

MonitorController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
namespace Spatie\UptimeMonitor\Http\Controller;
3
4
use Illuminate\Foundation\Validation\ValidatesRequests;
5
use Illuminate\Http\Request;
6
use Illuminate\Routing\Controller;
7
use Spatie\UptimeMonitor\Models\Monitor;
8
use Spatie\Url\Url;
9
10
class MonitorController extends Controller
11
{
12
    use ValidatesRequests;
13
14
    /**
15
     * Display a listing of the resource.
16
     *
17
     * @return \Illuminate\Http\Response
18
     */
19
    public function index()
20
    {
21
        return Monitor::all();
22
    }
23
24
    /**
25
     * Store a newly created resource in storage.
26
     *
27
     * @param  \Illuminate\Http\Request $request
28
     * @return \Illuminate\Http\Response
29
     */
30
    public function store(Request $request)
31
    {
32
        $this->validate($request, config('laravel-uptime-monitor.restAPI.validationRules'));
33
        $url = Url::fromString($request->get('url'));
34
        Monitor::create([
35
            'url' => trim($url, '/'),
36
            'look_for_string' => $request->get('look_for_string') ?? '',
37
            'uptime_check_method' => $request->has('look_for_string') ? 'get' : 'head',
38
            'certificate_check_enabled' => $url->getScheme() === 'https',
39
            'uptime_check_interval_in_minutes' => config('laravel-uptime-monitor.uptime_check.run_interval_in_minutes'),
40
        ]);
41
        return response()->json(['created' => true]);
42
    }
43
44
    /**
45
     * Display the specified resource.
46
     *
47
     * @param  int $id
48
     * @return \Illuminate\Http\Response
49
     */
50
    public function show($id)
51
    {
52
        return Monitor::findOrFail($id);
53
    }
54
55
    /**
56
     * Update the specified resource in storage.
57
     *
58
     * @param  \Illuminate\Http\Request $request
59
     * @param  int $id
60
     * @return \Illuminate\Http\Response
61
     */
62
    public function update(Request $request, $id)
63
    {
64
        $this->validate($request, config('laravel-uptime-monitor.restAPI.validationRules'));
65
66
        $monitor = Monitor::findOrFail($id);
67
        $url = Url::fromString($request->get('url'));
68
        $look_for_string = ($request->has('look_for_string')) ? $request->get('look_for_string') : $monitor->look_for_string;
69
        $monitor->update([
70
            'url' => $request->get('url'),
71
            'look_for_string' => $look_for_string,
72
            'uptime_check_method' => $request->has('look_for_string') ? 'get' : 'head',
73
            'certificate_check_enabled' => $url->getScheme() === 'https',
74
        ]);
75
        return response()->json(['updated' => true]);
76
    }
77
78
    /**
79
     * Remove the specified resource from storage.
80
     *
81
     * @param  int $id
82
     * @return \Illuminate\Http\Response
83
     */
84
    public function destroy($id)
85
    {
86
        $monitor = Monitor::findOrFail($id);
87
        $monitor->delete();
88
        return response()->json(['deleted' => true]);
89
    }
90
}
91