Completed
Push — master ( 195b94...7a36f1 )
by Mohamed
04:50
created

CheckForMaintenanceMode   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

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

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
    public function handle(Request $request, Closure $next)
34
    {
35
        $siteDown = $this->app->isDownForMaintenance();
36
        $isLogin  = $request->is('/', 'logout', 'signin');
37
38
        // Allow admin & login page to always view the site event in maintenance mode
39
        if ($siteDown && !$isLogin && ($this->auth->guest() || !$this->getLoggedUser()->isAdmin())) {
40
            throw new HttpException(503);
41
        }
42
43
        // Show message to administrator
44
        if ($siteDown) {
45
            $this->app['session']->flash('notice-error', trans('tinyissue.site_maintenance_message'));
46
        }
47
48
        return $next($request);
49
    }
50
}
51