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

CriticalHeaderChecker::checkHeader()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.2
cc 4
eloc 8
nc 4
nop 3
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