Issues (157)

app/Http/Middleware/LinkId.php (3 issues)

1
<?php
2
3
namespace App\Http\Middleware;
4
5
use Closure;
6
use Auth;
7
use App\Models\Link;
8
use Illuminate\Http\Request;
9
10
class LinkId
11
{
12
    public function handle($request, Closure $next)
13
    {
14
        $linkId = $request->route('id');
15
        $user = Auth::user();
16
    
17
        $link = Link::find($linkId);
18
    
19
        if (!$link) {
20
            return abort(404);
0 ignored issues
show
Are you sure the usage of abort(404) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
21
        }
22
    
23
        if ($user->id != $link->user_id) {
0 ignored issues
show
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
24
            return abort(403);
0 ignored issues
show
Are you sure the usage of abort(403) is correct as it seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
25
        }
26
    
27
        return $next($request);
28
    }
29
}
30