Completed
Push — develop ( 64a224...17d645 )
by Florent
03:11
created

CheckerManager::addClaimChecker()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 2
eloc 3
nc 2
nop 2
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 SpomkyLabs\JoseBundle\Service;
13
14
use Assert\Assertion;
15
use Jose\Checker\ClaimCheckerInterface;
16
use Jose\Checker\HeaderCheckerInterface;
17
18
final class CheckerManager
19
{
20
    /**
21
     * @var \Jose\Checker\ClaimCheckerInterface[]
22
     */
23
    private $claim_checkers = [];
24
    
25
    /**
26
     * @var \Jose\Checker\HeaderCheckerInterface[]
27
     */
28
    private $header_checkers = [];
29
30
    /**
31
     * @param \Jose\Checker\ClaimCheckerInterface $checker
32
     * @param string                              $alias
33
     */
34
    public function addClaimChecker(ClaimCheckerInterface $checker, $alias)
35
    {
36
        if (!array_key_exists($alias, $this->claim_checkers)) {
37
            $this->claim_checkers[$alias] = $checker;
38
        }
39
    }
40
41
    /**
42
     * @param \Jose\Checker\HeaderCheckerInterface $checker
43
     * @param string                               $alias
44
     */
45
    public function addHeaderChecker(HeaderCheckerInterface $checker, $alias)
46
    {
47
        if (!array_key_exists($alias, $this->header_checkers)) {
48
            $this->header_checkers[$alias] = $checker;
49
        }
50
    }
51
52
    /**
53
     * @param string[] $selected_claim_checkers
54
     *
55
     * @return \Jose\Checker\ClaimCheckerInterface[]
56
     */
57 View Code Duplication
    public function getSelectedClaimChecker(array $selected_claim_checkers)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
58
    {
59
        $result = [];
60
        foreach ($selected_claim_checkers as $alias) {
61
            Assertion::keyExists($this->claim_checkers, $alias, sprintf('The claim checker alias "%s" is not supported.', $alias));
62
            $result[] = $this->claim_checkers[$alias];
63
        }
64
        
65
        return $result;
66
    }
67
68
    /**
69
     * @param string[] $selected_header_checkers
70
     *
71
     * @return \Jose\Checker\HeaderCheckerInterface[]
72
     */
73 View Code Duplication
    public function getSelectedHeaderChecker(array $selected_header_checkers)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74
    {
75
        $result = [];
76
        foreach ($selected_header_checkers as $alias) {
77
            Assertion::keyExists($this->header_checkers, $alias, sprintf('The header checker alias "%s" is not supported.', $alias));
78
            $result[] = $this->header_checkers[$alias];
79
        }
80
        
81
        return $result;
82
    }
83
}
84