Code Duplication    Length = 31-31 lines in 2 locations

Service/AlgorithmManager.php 1 location

@@ 17-47 (lines=31) @@
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
    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

Service/CompressionManager.php 1 location

@@ 17-47 (lines=31) @@
14
use Assert\Assertion;
15
use Jose\Compression\CompressionInterface;
16
17
final class CompressionManager
18
{
19
    /**
20
     * @var \Jose\Compression\CompressionInterface[]
21
     */
22
    private $compression_methods = [];
23
24
    public function addCompressionMethod(CompressionInterface $compression_method)
25
    {
26
        $name = $compression_method->getMethodName();
27
        if (!array_key_exists($name, $this->compression_methods)) {
28
            $this->compression_methods[$name] = $compression_method;
29
        }
30
    }
31
32
    /**
33
     * @param string[] $selected_compression_methods
34
     *
35
     * @return \Jose\Compression\CompressionInterface[]
36
     */
37
    public function getSelectedCompressionMethods(array $selected_compression_methods)
38
    {
39
        $result = [];
40
        foreach ($selected_compression_methods as $method) {
41
            Assertion::keyExists($this->compression_methods, $method, sprintf('The compression method "%s" is not supported.', $method));
42
            $result[] = $this->compression_methods[$method];
43
        }
44
        
45
        return $result;
46
    }
47
}
48