Failed Conditions
Push — master ( 8befd5...3eda38 )
by Florent
03:20
created

JWETokenHeaderChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 4 1
A retrieveTokenHeaders() 0 18 3
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\Encryption;
15
16
use Jose\Component\Checker\TokenTypeHeaderCheckerInterface;
17
use Jose\Component\Core\JWTInterface;
18
19
/**
20
 * Class JWETokenHeaderChecker.
21
 */
22
final class JWETokenHeaderChecker implements TokenTypeHeaderCheckerInterface
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function supports(JWTInterface $jwt): bool
28
    {
29
        return $jwt instanceof JWE;
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function retrieveTokenHeaders(JWTInterface $jwt, int $component, array &$protectedHeader, array &$unprotectedHeader): void
36
    {
37
        if (!$jwt instanceof JWE) {
38
            return;
39
        }
40
41
        if ($component > $jwt->countRecipients()) {
42
            throw new \InvalidArgumentException('Unknown recipient index.');
43
        }
44
        $protectedHeader = $jwt->getSharedProtectedHeaders();
45
        $unprotectedHeader = $jwt->getSharedHeaders();
46
        $recipient = $jwt->getRecipient($component)->getHeaders();
47
48
        $unprotectedHeader = array_merge(
49
            $unprotectedHeader,
50
            $recipient
51
        );
52
    }
53
}
54