CorsMiddleware   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 10
c 0
b 0
f 0
wmc 3
lcom 0
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 16 3
1
<?php
2
3
namespace Bludata\Lumen\Http\Middleware;
4
5
use Closure;
6
7
class CorsMiddleware
8
{
9
    /**
10
     * Handle an incoming request.
11
     *
12
     * @param \Illuminate\Http\Request $request
13
     * @param \Closure                 $next
14
     *
15
     * @return mixed
16
     */
17
    public function handle($request, Closure $next)
18
    {
19
        if (env('APP_ENV') !== 'testing') {
20
            header('Access-Control-Allow-Origin: *');
21
            header('Access-Control-Allow-Credentials: true');
22
            header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 84 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
23
            header('Access-Control-Allow-Headers: Origin, Content-Type, Accept, Authorization, token, _');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 80 characters; contains 106 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
24
            header('Content-Type: application/json; charset=utf-8');
25
        }
26
27
        if ($request->getRealMethod() == 'OPTIONS') {
28
            return new \Illuminate\Http\Response('OK', 200);
29
        }
30
31
        return $next($request);
32
    }
33
}
34