Passed
Push — master ( e492ae...dd1db9 )
by Haven
02:26
created

Guard::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 3
crap 2
1
<?php
2
3
namespace 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
}