DiscussMaintenance::handle()   B
last analyzed

Complexity

Conditions 7
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 7
eloc 8
nc 3
nop 2
dl 0
loc 17
rs 8.8333
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Xetaravel\Http\Middleware;
6
7
use Closure;
8
use Illuminate\Http\RedirectResponse;
9
use Illuminate\Http\Request;
10
use Illuminate\Support\Facades\Auth;
11
use Masmerise\Toaster\Toaster;
12
use Psr\Container\ContainerExceptionInterface;
13
use Psr\Container\NotFoundExceptionInterface;
14
15
class DiscussMaintenance
16
{
17
    /**
18
     * Handle an incoming request.
19
     *
20
     * @param Request $request
21
     * @param Closure $next
22
     *
23
     * @return RedirectResponse|mixed
24
     *
25
     * @throws ContainerExceptionInterface
26
     * @throws NotFoundExceptionInterface
27
     */
28
    public function handle(Request $request, Closure $next): mixed
29
    {
30
        // If discuss is disabled and the user is not admin.
31
        if ((!Auth::user() && !settings('discuss_enabled')) ||
32
            (!settings('discuss_enabled') && !Auth::user()->hasPermissionTo('manage discuss conversation'))
0 ignored issues
show
Bug introduced by
The method hasPermissionTo() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of said class. However, the method does not exist in Illuminate\Auth\GenericUser. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
            (!settings('discuss_enabled') && !Auth::user()->/** @scrutinizer ignore-call */ hasPermissionTo('manage discuss conversation'))
Loading history...
33
        ) {
34
            return redirect()
35
                        ->route('page.index')
0 ignored issues
show
Bug introduced by
The method route() does not exist on Illuminate\Routing\Redirector. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
                        ->/** @scrutinizer ignore-call */ route('page.index')

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...
36
                        ->error('The discuss system is temporarily disabled.');
37
        }
38
39
        // If discuss is disabled and the user is admin.
40
        if (!settings('discuss_enabled') && Auth::user()->hasPermissionTo('manage discuss conversation')) {
41
            Toaster::error('The discuss system is temporarily disabled.');
42
        }
43
44
        return $next($request);
45
    }
46
}
47