Passed
Push — master ( c44d00...13b3c2 )
by David
53s
created

HardCodedTargetOrigins   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 0
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 4 1
1
<?php
2
3
4
namespace TheCodingMachine\Middlewares\OriginFetchers;
5
6
use Psr\Http\Message\ServerRequestInterface;
7
use TheCodingMachine\Middlewares\CsrfHeaderCheckMiddlewareException;
8
9
/**
10
 * A set of hard coded target origins.
11
 * To be used if your application is behind a proxy (thus preventing the use of "HostHeader" class.
12
 */
13
class HardCodedTargetOrigins implements TargetOriginInterface
14
{
15
    /**
16
     * @var \string[]
17
     */
18
    private $origins;
19
20
    /**
21
     * @param \string[] ...$origins A set of domain names for YOUR application.
22
     */
23
    public function __construct(string ...$origins)
24
    {
25
        $this->origins = $origins;
0 ignored issues
show
Documentation Bug introduced by
It seems like $origins of type array<integer,array<integer,object<string>>> is incompatible with the declared type array<integer,object<string>> of property $origins.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
26
    }
27
28
    /**
29
     * Returns an array of domain names for your application.
30
     * If the "source" origin matches one of these origins, the request is valid.
31
     *
32
     * @return string[]
33
     * @throws \TheCodingMachine\Middlewares\CsrfHeaderCheckMiddlewareException
34
     */
35
    public function __invoke(ServerRequestInterface $request): array
36
    {
37
        return $this->origins;
38
    }
39
}
40