ApiHeaderInject::handle()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.7333
c 0
b 0
f 0
cc 3
nc 4
nop 2
1
<?php
2
3
namespace Bhavingajjar\LaravelApiGenerator\Middleware;
4
5
use Closure;
6
use Illuminate\Support\Facades\Config;
7
8
class ApiHeaderInject
9
{
10
    public function handle($request, Closure $next)
11
    {
12
        if (config('laravel-api-generator.json_response')) {
13
            $request->headers->add([
14
                'Accept'=>'application/json',
15
            ]);
16
        }
17
        if (config('laravel-api-generator.allow_cross_origin')) {
18
            $request->headers->add([
19
                'Access-Control-Allow-Origin' => '*',
20
                'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS',
21
            ]);
22
        }
23
24
        return $next($request);
25
    }
26
}
27