AlgorithmManager   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addAlgorithm() 0 7 2
A getSelectedAlgorithmMethods() 0 10 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\Algorithm\JWAInterface;
16
17
final class AlgorithmManager
18
{
19
    /**
20
     * @var \Jose\Algorithm\JWAInterface[]
21
     */
22
    private $algorithms = [];
23
24
    /**
25
     * @param \Jose\Algorithm\JWAInterface $algorithm
26
     */
27
    public function addAlgorithm(JWAInterface $algorithm)
28
    {
29
        $name = $algorithm->getAlgorithmName();
30
        if (!array_key_exists($name, $this->algorithms)) {
31
            $this->algorithms[$name] = $algorithm;
32
        }
33
    }
34
35
    /**
36
     * @param string[] $selected_algorithms
37
     *
38
     * @return \Jose\Algorithm\JWAInterface[]
39
     */
40
    public function getSelectedAlgorithmMethods(array $selected_algorithms)
41
    {
42
        $result = [];
43
        foreach ($selected_algorithms as $algorithm) {
44
            Assertion::keyExists($this->algorithms, $algorithm, sprintf('The algorithm "%s" is not supported.', $algorithm));
45
            $result[] = $this->algorithms[$algorithm];
46
        }
47
48
        return $result;
49
    }
50
}
51