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

CorsAllowAll::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 1
cts 1
cp 1
crap 1
rs 10
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