Passed
Pull Request — develop (#49)
by Pieter van der
10:27
created

Tiqr_UserStorage_Encryption   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 63.64%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
c 1
b 0
f 0
dl 0
loc 29
ccs 7
cts 11
cp 0.6364
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getEncryption() 0 15 3
1
<?php
2
/**
3
 * This file is part of the tiqr project.
4
 * 
5
 * The tiqr project aims to provide an open implementation for 
6
 * authentication using mobile devices. It was initiated by 
7
 * SURFnet and developed by Egeniq.
8
 *
9
 * More information: http://www.tiqr.org
10
 *
11
 * @author Peter Verhage <[email protected]>
12
 * 
13
 * @package tiqr
14
 *
15
 * @license New BSD License - See LICENSE file for details.
16
 *
17
 * @copyright (C) 2010-2012 SURFnet BV
18
 */
19
20
use Psr\Log\LoggerInterface;
21
22
/**
23
 * Class implementing a factory for user storage encryption.
24
 *
25
 * @author peter
26
 */
27
class Tiqr_UserStorage_Encryption
28
{
29
    /**
30
     * Get an encryption handler of a certain type (default: 'file')
31
     *
32
     * @param String $type The type of storage to create. Supported
33
     *                     types are 'dummy', 'mcrypt' or the full class name.
34
     * @param array $options The options to pass to the storage
35
     *                       instance. See the documentation
36
     *                       in the Encryption subdirectory for
37
     *                       options per type.
38
     *
39
     * @return Tiqr_UserSecretStorage_Encryption_Interface
40
     */
41 11
    public static function getEncryption(LoggerInterface $logger, string $type="dummy", array $options=array()): Tiqr_UserSecretStorage_Encryption_Interface
42
    {
43 11
        $logger->info(sprintf('Using %s as UserStorage encryption type', $type));
44 11
        switch ($type) {
45 11
            case "dummy":
46 11
                $instance = new Tiqr_UserSecretStorage_Encryption_Dummy($options);
47 11
                break;
48
            case "mcrypt":
49
                $instance = new Tiqr_UserSecretStorage_Encryption_Mcrypt($options);
50
                break;
51
            default: 
52
                $instance = new $type($options);
53
        }
54
        
55 11
        return $instance;
56
    }
57
}
58