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

AlgorithmManager   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addAlgorithm() 7 7 2
A getSelectedAlgorithmMethods() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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