Completed
Push — master ( 6c40ed...665ea8 )
by sebastian
01:26
created

CompressionAlgorithms_Registry.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php namespace jwe\compression_algorithms;
2
/**
3
 * Copyright 2015 OpenStack Foundation
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 * http://www.apache.org/licenses/LICENSE-2.0
8
 * Unless required by applicable law or agreed to in writing, software
9
 * distributed under the License is distributed on an "AS IS" BASIS,
10
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
 * See the License for the specific language governing permissions and
12
 * limitations under the License.
13
 **/
14
use jwe\compression_algorithms\impl\Deflate;
15
use jwe\compression_algorithms\impl\ZLib;
16
use jwe\compression_algorithms\impl\GZip;
17
/**
18
 * Class CompressionAlgorithms_Registry
19
 * @package jwe\compression_algorithms
20
 */
21 View Code Duplication
final class CompressionAlgorithms_Registry {
0 ignored issues
show
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...
22
23
    /**
24
     * @var CompressionAlgorithms_Registry
25
     */
26
    private static $instance;
27
28
    private $algorithms = [];
29
30
    private function __construct(){
31
32
        $this->algorithms[CompressionAlgorithmsNames::Deflate] = new Deflate;
33
        $this->algorithms[CompressionAlgorithmsNames::GZip]    = new GZip;
34
        $this->algorithms[CompressionAlgorithmsNames::ZLib]    = new ZLib;
35
36
    }
37
38
    private function __clone(){}
39
40
    /**
41
     * @return CompressionAlgorithms_Registry
42
     */
43
    public static function getInstance(){
44
        if(!is_object(self::$instance)){
45
            self::$instance = new CompressionAlgorithms_Registry();
46
        }
47
        return self::$instance;
48
    }
49
50
    /**
51
     * @param string $alg
52
     * @return bool
53
     */
54
    public function isSupported($alg){
55
        return array_key_exists($alg, $this->algorithms);
56
    }
57
58
    /**
59
     * @param $alg
60
     * @return null|CompressionAlgorithm
61
     */
62
    public function get($alg){
63
        if(!$this->isSupported($alg)) return null;
64
        return $this->algorithms[$alg];
65
    }
66
}