Completed
Push — master ( e20120...0bdab5 )
by Haven
01:57
created

Guard   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 29
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A __invoke() 0 8 2
A getResponseHeradersOrigin() 0 4 1
1
<?php
2
3
namespace HavenShen\Slim\Cors;
4
5
class Guard
6
{
7
8
    public $settings;
9
10
    protected $response;
11
12 1
    public function __construct($settings = [])
13
    {
14 1
        $this->settings = array_merge([
15 1
            'Access-Control-Allow-Origin' => '*',
16
            'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS'
17
        ],$settings);
18 1
    }
19
20 1
    public function __invoke($request, $response, $next)
21
    {
22 1
        $this->response = $next($request, $response);
23 1
        foreach ($this->settings as $key => $value) {
24 1
            $this->response = $this->response->withAddedHeader($key, $value);
25
        }
26 1
        return $this->response;
27
    }
28
29 1
    public function getResponseHeradersOrigin()
30
    {
31 1
        return $this->response->getHeaderLine('Access-Control-Allow-Origin');
32
    }
33
}