VerifyFirstPartyClientIp::handle()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.9332
cc 3
nc 2
nop 3
crap 3
1
<?php
2
3
4
namespace ReleaseProtection\Http\Middleware;
5
6
use Closure;
7
8
class VerifyFirstPartyClientIp
9
{
10
11
    /**
12
     * Handle an incoming request.
13
     *
14
     * @param \Illuminate\Http\Request $request
15
     * @param Closure $next
16
     * @param string $type
17
     *
18
     * @return mixed
19
     */
20 3
    public function handle($request, Closure $next, $type = 'default')
21
    {
22 3
        $allowIPs = config('release-protection.ip.ips.' . $type, config('release-protection.ip.ips.default'));
23
        if (
24 3
            app()->environment(
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

24
            app()->/** @scrutinizer ignore-call */ environment(
Loading history...
25 3
                config('release-protection.ip.envs.' . $type, config('release-protection.ip.envs.default'))
26 3
            ) &&
27 3
            !in_array($request->ip(), $allowIPs)
28
        ) {
29 2
            abort(
30 2
                config('release-protection.ip.status.restricted.' . $type, config('release-protection.ip.status.restricted.default')),
31 2
                __(config('release-protection.ip.msg.restricted.' . $type, config('release-protection.ip.msg.restricted.default')))
0 ignored issues
show
Bug introduced by
It seems like __(config('release-prote....restricted.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

31
                /** @scrutinizer ignore-type */ __(config('release-protection.ip.msg.restricted.' . $type, config('release-protection.ip.msg.restricted.default')))
Loading history...
32 2
            );
33
        }
34
35 1
        return $next($request);
36
    }
37
}
38