RedirectToHttps::handle()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 23
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 13
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 23
ccs 12
cts 12
cp 1
crap 5
rs 9.5222
1
<?php
2
3
namespace ForceHttps\Middleware;
4
5
use Closure;
6
use Illuminate\Http\Request;
7
8
class RedirectToHttps
9
{
10 3
    public function handle(Request $request, Closure $next)
11
    {
12
        if (
13 3
            !$request->isSecure()
14
            && (
15 3
                config('force-https.conditions.always')
16 3
                || app()->environment(config('force-https.conditions.envs'))
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

16
                || app()->/** @scrutinizer ignore-call */ environment(config('force-https.conditions.envs'))
Loading history...
17
            )
18
        ) {
19 2
            $path = $request->path();
20 2
            if (config('force-https.redirect.query', false)) {
21
                // Also affect merged data
22 1
                $path .= '?' . http_build_query($request->query->all());
23
            }
24
25 2
            return redirect()->secure(
26 2
                $path,
27 2
                config('force-https.redirect.status', false),
28 2
                config('force-https.redirect.headers', []),
29
            );
30
        }
31
32 1
        return $next($request);
33
    }
34
}
35