CorsMiddleware::handle()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 4
nop 2
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
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