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

CompositeTargetOrigin::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
4
namespace TheCodingMachine\Middlewares\OriginFetchers;
5
6
use Psr\Http\Message\ServerRequestInterface;
7
8
class CompositeTargetOrigin implements TargetOriginInterface
9
{
10
    /**
11
     * @var TargetOriginInterface[]
12
     */
13
    private $targetOrigins;
14
15
    /**
16
     * @param TargetOriginInterface[] ...$targetOrigins
17
     */
18
    public function __construct(TargetOriginInterface ...$targetOrigins)
19
    {
20
        $this->targetOrigins = $targetOrigins;
0 ignored issues
show
Documentation Bug introduced by
It seems like $targetOrigins of type array<integer,array<inte...argetOriginInterface>>> is incompatible with the declared type array<integer,object<The...TargetOriginInterface>> of property $targetOrigins.

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...
21
    }
22
23
    /**
24
     * Returns an array of allowed domain names.
25
     * If the "source" origin matches one of these origins, the request is valid.
26
     *
27
     * @return string[]
28
     */
29
    public function __invoke(ServerRequestInterface $request): array
30
    {
31
        $targetOrigins = [];
32
33
        foreach ($this->targetOrigins as $targetOrigin) {
34
            $targetOrigins = array_merge($targetOrigins, $targetOrigin($request));
35
        }
36
37
        return $targetOrigins;
38
    }
39
}
40