CheckForPartialMaintenanceMode   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 4
dl 0
loc 30
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 4
1
<?php
2
3
namespace DigiFactory\PartialDown\Middleware;
4
5
use Closure;
6
use Illuminate\Foundation\Http\Exceptions\MaintenanceModeException;
7
use Illuminate\Support\Str;
8
use Symfony\Component\HttpFoundation\IpUtils;
9
10
class CheckForPartialMaintenanceMode
11
{
12
    /**
13
     * Handle an incoming request.
14
     *
15
     * @param \Illuminate\Http\Request $request
16
     * @param \Closure $next
17
     * @param string $part
18
     * @return mixed
19
     *
20
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
21
     * @throws \Illuminate\Foundation\Http\Exceptions\MaintenanceModeException
22
     */
23
    public function handle($request, Closure $next, $part)
24
    {
25
        $lockFilename = 'framework/partial-down-'.Str::slug($part);
26
27
        if (file_exists(storage_path($lockFilename))) {
28
            $data = json_decode(file_get_contents(storage_path($lockFilename)), true);
29
30
            if (isset($data['allowed']) && IpUtils::checkIp($request->ip(), (array) $data['allowed'])) {
31
                return $next($request);
32
            }
33
34
            throw new MaintenanceModeException($data['time'], $data['retry'], $data['message']);
35
        }
36
37
        return $next($request);
38
    }
39
}
40