Test Failed
Pull Request — master (#106)
by Dmitriy
13:12 queued 36s
created

CorsAllowAll   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 27
ccs 11
cts 11
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A process() 0 20 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Middleware;
6
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\MiddlewareInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use Yiisoft\ErrorHandler\HeadersProvider;
0 ignored issues
show
Bug introduced by
The type Yiisoft\ErrorHandler\HeadersProvider was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Yiisoft\Http\Header;
13
14
/**
15
 * Adds Cross-Origin Resource Sharing (CORS) headers allowing everything to the response.
16
 */
17
final class CorsAllowAll implements MiddlewareInterface
18 1
{
19
    public function __construct(
20 1
        private HeadersProvider $headersProvider
21
    ) {
22 1
    }
23 1
24 1
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
25 1
    {
26 1
        $this->headersProvider->add(Header::ACCESS_CONTROL_ALLOW_ORIGIN, '*');
27 1
        $this->headersProvider->add(Header::ACCESS_CONTROL_ALLOW_METHODS, 'GET,OPTIONS,HEAD,POST,PUT,PATCH,DELETE');
28 1
        $this->headersProvider->add(Header::ACCESS_CONTROL_ALLOW_HEADERS, '*');
29 1
        $this->headersProvider->add(Header::ACCESS_CONTROL_EXPOSE_HEADERS, '*');
30 1
        $this->headersProvider->add(Header::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true');
31
        $this->headersProvider->add(Header::ACCESS_CONTROL_MAX_AGE, '86400');
32
33
        $response = $handler->handle($request);
34
35
        return $response
36
            ->withHeader(Header::ALLOW, '*')
37
            ->withHeader(Header::VARY, 'Origin')
38
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_ORIGIN, '*')
39
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_METHODS, 'GET,OPTIONS,HEAD,POST,PUT,PATCH,DELETE')
40
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_HEADERS, '*')
41
            ->withHeader(Header::ACCESS_CONTROL_EXPOSE_HEADERS, '*')
42
            ->withHeader(Header::ACCESS_CONTROL_ALLOW_CREDENTIALS, 'true')
43
            ->withHeader(Header::ACCESS_CONTROL_MAX_AGE, '86400');
44
    }
45
}
46