Completed
Push — develop ( 4c84f9...64a224 )
by Florent
05:18
created

AlgorithmManager::addAlgorithm()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 7
loc 7
rs 9.4285
cc 2
eloc 4
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
    public function addAlgorithm(JWAInterface $algorithm)
25
    {
26
        $name = $algorithm->getAlgorithmName();
27
        if (!array_key_exists($name, $this->algorithms)) {
28
            $this->algorithms[$name] = $algorithm;
29
        }
30
    }
31
32
    /**
33
     * @param string[] $selected_algorithms
34
     *
35
     * @return \Jose\Algorithm\JWAInterface[]
36
     */
37
    public function getSelectedAlgorithmMethods(array $selected_algorithms)
38
    {
39
        $result = [];
40
        foreach ($selected_algorithms as $algorithm) {
41
            Assertion::keyExists($this->algorithms, $algorithm, sprintf('The algorithm "%s" is not supported.', $algorithm));
42
            $result[] = $this->algorithms[$algorithm];
43
        }
44
        
45
        return $result;
46
    }
47
}
48