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

getSelectedCompressionMethods()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 10
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 10
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\Compression\CompressionInterface;
16
17 View Code Duplication
final class CompressionManager
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\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