Failed Conditions
Push — master ( d841d5...f9383a )
by Florent
02:06
created

JWSTokenSupport::retrieveTokenHeaders()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * The MIT License (MIT)
7
 *
8
 * Copyright (c) 2014-2017 Spomky-Labs
9
 *
10
 * This software may be modified and distributed under the terms
11
 * of the MIT license.  See the LICENSE file for details.
12
 */
13
14
namespace Jose\Component\Signature;
15
16
use Jose\Component\Checker\TokenTypeSupportInterface;
17
use Jose\Component\Core\JWTInterface;
18
19
/**
20
 * Class JWSTokenSupport.
21
 */
22
final class JWSTokenSupport implements TokenTypeSupportInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function supports(JWTInterface $jwt): bool
28
    {
29
        return $jwt instanceof JWS;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function retrieveTokenHeaders(JWTInterface $jwt, int $component, array &$protectedHeader, array &$unprotectedHeader): void
36
    {
37
        if (!$jwt instanceof JWS) {
38
            return;
39
        }
40
41
        if ($component > $jwt->countSignatures()) {
42
            throw new \InvalidArgumentException('Unknown signature index.');
43
        }
44
        $protectedHeader = $jwt->getSignature($component)->getProtectedHeaders();
45
        $unprotectedHeader = $jwt->getSignature($component)->getHeaders();
46
    }
47
}
48