Completed
Push — master ( b015a1...0e1003 )
by Abdelrahman
49:45
created

Clockwork   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 17 3
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Cortex Foundation Module.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Cortex Foundation Module
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
declare(strict_types=1);
17
18
namespace Cortex\Foundation\Http\Middleware;
19
20
use Closure;
21
use Exception;
22
use Illuminate\Foundation\Application;
23
24
class Clockwork
25
{
26
    /**
27
     * The Laravel Application.
28
     *
29
     * @var Application
30
     */
31
    protected $app;
32
33
    /**
34
     * Create a new middleware instance.
35
     *
36
     * @param Application $app
37
     *
38
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
39
     */
40
    public function __construct(Application $app)
41
    {
42
        $this->app = $app;
43
    }
44
45
    /**
46
     * Handle an incoming request.
47
     *
48
     * @param \Illuminate\Http\Request $request
49
     * @param \Closure                 $next
50
     *
51
     * @return mixed
52
     */
53
    public function handle($request, Closure $next)
54
    {
55
        if (app()->environment() !== 'production') {
56
            $this->app['config']->set('clockwork::config.middleware', true);
57
58
            try {
59
                $response = $next($request);
60
            } catch (Exception $e) {
61
                $this->app['Illuminate\Contracts\Debug\ExceptionHandler']->report($e);
62
                $response = $this->app['Illuminate\Contracts\Debug\ExceptionHandler']->render($request, $e);
63
            }
64
65
            return $this->app['clockwork.support']->process($request, $response);
66
        }
67
68
        return $next($request);
69
    }
70
}
71