Completed
Branch master (7a36f1)
by Mohamed
04:08
created

CheckForMaintenanceMode   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 75%

Importance

Changes 3
Bugs 2 Features 1
Metric Value
wmc 6
c 3
b 2
f 1
lcom 1
cbo 6
dl 0
loc 30
ccs 6
cts 8
cp 0.75
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 17 6
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Http\Middleware;
13
14
use Closure;
15
use Symfony\Component\HttpKernel\Exception\HttpException;
16
use Illuminate\Http\Request;
17
18
/**
19
 * @author Mohamed Alsharaf <[email protected]>
20
 */
21
class CheckForMaintenanceMode extends MiddlewareAbstract
22
{
23
    /**
24
     * Handle an incoming request.
25
     *
26
     * @param \Illuminate\Http\Request $request
27
     * @param \Closure                 $next
28
     *
29
     * @return mixed
30
     *
31
     * @throws \Symfony\Component\HttpKernel\Exception\HttpException
32
     */
33 63
    public function handle(Request $request, Closure $next)
34
    {
35 63
        $siteDown = $this->app->isDownForMaintenance();
36 63
        $isLogin  = $request->is('/', 'logout', 'signin');
37
38
        // Allow admin & login page to always view the site event in maintenance mode
39 63
        if ($siteDown && !$isLogin && ($this->auth->guest() || !$this->getLoggedUser()->isAdmin())) {
40
            throw new HttpException(503);
41
        }
42
43
        // Show message to administrator
44 63
        if ($siteDown) {
45
            $this->app['session']->flash('notice-error', trans('tinyissue.site_maintenance_message'));
46
        }
47
48 63
        return $next($request);
49
    }
50
}
51