Passed
Pull Request — develop (#27)
by Michiel
06:19
created

Tiqr_UserStorage_Encryption   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 61.53%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 14
c 1
b 0
f 0
dl 0
loc 31
ccs 8
cts 13
cp 0.6153
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getEncryption() 0 17 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 1
require_once 'Tiqr/UserStorage/Encryption/Interface.php';
23
24
/**
25
 * Class implementing a factory for user storage encryption.
26
 *
27
 * @author peter
28
 */
29
class Tiqr_UserStorage_Encryption
30
{
31
    /**
32
     * Get an encryption handler of a certain type (default: 'file')
33
     *
34
     * @param String $type The type of storage to create. Supported
35
     *                     types are 'dummy', 'mcrypt' or the full class name.
36
     * @param array $options The options to pass to the storage
37
     *                       instance. See the documentation
38
     *                       in the Encryption subdirectory for
39
     *                       options per type.
40
     *
41
     * @return Tiqr_UserStorage_Encryption_Interface
42
     */
43 3
    public static function getEncryption(LoggerInterface $logger, $type="dummy", $options=array())
44
    {
45 3
        $logger->info(sprintf('Using %s as UserStorage encryption type', $type));
46 3
        switch ($type) {
47 3
            case "dummy":
48 3
                require_once("Tiqr/UserStorage/Encryption/Dummy.php");
49 3
                $instance = new Tiqr_UserStorage_Encryption_Dummy($options);
50 3
                break;
51
            case "mcrypt":
52
                require_once("Tiqr/UserStorage/Encryption/Mcrypt.php");
53
                $instance = new Tiqr_UserStorage_Encryption_Mcrypt($options);
54
                break;
55
            default: 
56
                $instance = new $type($options);
57
        }
58
        
59 3
        return $instance;
60
    }
61
}
62