Completed
Push — master ( d51485...4815df )
by yoshihiro
01:33
created

TokenExtractorResolver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Piotzkhider\FirebaseAuthenticationModule\Extractor;
6
7
use Aura\Web\Request;
8
use Piotzkhider\FirebaseAuthenticationModule\Annotation\Extractors;
9
use Piotzkhider\FirebaseAuthenticationModule\Exception\TokenNotFound;
10
11
class TokenExtractorResolver
12
{
13
    /**
14
     * @var TokenExtractorInterface[]
15
     */
16
    private $extractors;
17
18
    /**
19
     * @Extractors()
20
     *
21
     * @var TokenExtractorInterface[]
22
     */
23 5
    public function __construct(array $extractors)
24
    {
25 5
        $this->extractors = $extractors;
26 5
    }
27
28 2
    public function resolve(Request $request): TokenExtractorInterface
29
    {
30 2
        foreach ($this->extractors as $extractor) {
31 2
            if ($extractor->supports($request)) {
32 2
                return $extractor;
33
            }
34
        }
35
36
        throw new TokenNotFound();
37
    }
38
}
39