Completed
Push — master ( 99a6c6...d8f4a1 )
by Florent
04:02
created

AlgorithmManager::getSelectedAlgorithmMethods()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 8
Ratio 80 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 8
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
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 View Code Duplication
final class AlgorithmManager
0 ignored issues
show
Duplication introduced by
This class 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...
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