Completed
Push — 6.0 ( f489c0...0362ee )
by liu
03:22
created

AllowCrossDomain   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 25
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 9 3
1
<?php
2
// +----------------------------------------------------------------------
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
declare (strict_types = 1);
12
13
namespace think\middleware;
14
15
use Closure;
16
use think\Request;
17
use think\Response;
18
19
class AllowCrossDomain
1 ignored issue
show
Coding Style introduced by
Missing doc comment for class AllowCrossDomain
Loading history...
20
{
21
    protected $header = [
22
        'Access-Control-Allow-Origin'  => '*',
23
        'Access-Control-Allow-Methods' => 'GET, POST, PATCH, PUT, DELETE',
24
        'Access-Control-Allow-Headers' => 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With',
25
    ];
26
27
    /**
28
     * 允许跨域请求
29
     * @access public
30
     * @param Request $request
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
31
     * @param Closure $next
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
32
     * @param array   $header
1 ignored issue
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
33
     * @return Response
34
     */
35
    public function handle($request, Closure $next, array $header = [])
36
    {
37
        $header = !empty($header) ? array_merge($this->header, $header) : $this->header;
38
39
        if ($request->method(true) == 'OPTIONS') {
40
            return Response::create()->code(204)->header($header);
41
        }
42
43
        return $next($request);
44
    }
45
}
46