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
01:56
created

MonitorController::show()   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 1
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([
0 ignored issues
show
Unused Code introduced by
$monitor 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...
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);
0 ignored issues
show
Bug introduced by
The method setStatusCode() does not seem to exist on object<Illuminate\Contra...outing\ResponseFactory>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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
}