Completed
Push — master ( ce5be5...cd6056 )
by Florent
02:40
created

CriticalHeaderChecker   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A checkHeader() 0 15 4
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Checker;
13
14
class CriticalHeaderChecker implements HeaderCheckerInterface
15
{
16
    /**
17
     * {@inheritdoc}
18
     */
19
    public function checkHeader(array $protected_headers, array $headers, array $checked_claims)
20
    {
21
        if (!array_key_exists('crit', $protected_headers)) {
22
            return;
23
        }
24
25
        if (!is_array($protected_headers['crit'])) {
26
            throw new \InvalidArgumentException('The parameter "crit" must be a list.');
27
        }
28
29
        $diff = array_diff($protected_headers['crit'], $checked_claims);
30
        if (!empty($diff)) {
31
            throw new \InvalidArgumentException(sprintf('One or more claims are marked as critical, but they are missing or not have not been checked (%s).', json_encode(array_values($diff))));
32
        }
33
    }
34
35
}
36