ChainExtractor::extractKey()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 4
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Damax\Bundle\ApiAuthBundle\Extractor;
6
7
use Symfony\Component\HttpFoundation\Request;
8
9
final class ChainExtractor implements Extractor
10
{
11
    /**
12
     * @var Extractor[]
13
     */
14
    private $extractors = [];
15
16
    public function __construct(array $extractors = [])
17
    {
18
        foreach ($extractors as $extractor) {
19
            $this->add($extractor);
20
        }
21
    }
22
23
    public function add(Extractor $extractor): void
24
    {
25
        $this->extractors[] = $extractor;
26
    }
27
28
    public function extractKey(Request $request): ?string
29
    {
30
        foreach ($this->extractors as $extractor) {
31
            if (null !== $key = $extractor->extractKey($request)) {
32
                return $key;
33
            }
34
        }
35
36
        return null;
37
    }
38
}
39