TestersEmailMiddleware   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 14
c 1
b 0
f 0
dl 0
loc 35
ccs 16
cts 16
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 23 5
1
<?php
2
3
4
namespace ReleaseProtection\Http\Middleware;
5
6
use Auth;
7
use Closure;
8
9
class TestersEmailMiddleware
10
{
11
12
    /**
13
     * Handle an incoming request.
14
     *
15
     * @param \Illuminate\Http\Request $request
16
     * @param Closure $next
17
     * @param string $guard
18
     *
19
     * @return mixed
20
     */
21 7
    public function handle($request, Closure $next, $guard = null)
22
    {
23 7
        if (app()->environment(config('release-protection.email.envs.' . $guard, config('release-protection.email.envs.default')))) {
0 ignored issues
show
introduced by
The method environment() does not exist on Illuminate\Container\Container. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

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

23
        if (app()->/** @scrutinizer ignore-call */ environment(config('release-protection.email.envs.' . $guard, config('release-protection.email.envs.default')))) {
Loading history...
24 7
            $user = Auth::guard($guard)->user();
25 7
            if (!$user) {
26 2
                abort(
27 2
                    config('release-protection.email.status.not_logged.' . $guard, config('release-protection.email.status.not_logged.default')),
28 2
                    __(config('release-protection.email.msg.not_logged.' . $guard, config('release-protection.email.msg.not_logged.default')))
0 ignored issues
show
Bug introduced by
It seems like __(config('release-prote....not_logged.default'))) can also be of type array; however, parameter $message of abort() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

28
                    /** @scrutinizer ignore-type */ __(config('release-protection.email.msg.not_logged.' . $guard, config('release-protection.email.msg.not_logged.default')))
Loading history...
29 2
                );
30
            }
31
32 5
            $allowEmails = config('release-protection.email.emails.' . $guard, config('release-protection.email.emails.default'));
33 5
            $allowEmails = array_map(fn ($e) => trim(strtolower($e)), $allowEmails);
34
35 5
            if (!$user->email || !in_array(strtolower($user->email), $allowEmails)) {
0 ignored issues
show
Bug introduced by
Accessing email on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
36 3
                abort(
37 3
                    config('release-protection.email.status.restricted.' . $guard, config('release-protection.email.status.restricted.default')),
38 3
                    __(config('release-protection.email.msg.restricted.' . $guard, config('release-protection.email.msg.restricted.default')))
39 3
                );
40
            }
41
        }
42
43 2
        return $next($request);
44
    }
45
}
46