Passed
Pull Request — develop (#50)
by Pieter van der
03:35
created

Tiqr_UserStorage_Encryption   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

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
/**
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: 'dummy')
31
     *
32
     * @param LoggerInterface $logger
33
     * @param String $type The type of storage to create. Supported types are 'dummy' (default)
34
     *                     or any class implementing Tiqr_UserSecretStorage_Encryption_Interface.
35
     *                     In that case $type should be the full class name.
36
     * @param array $options The options to pass to the storage instance. See the documentation
37
     *                       in the Encryption subdirectory for options per type.
38
     *
39
     * @return Tiqr_UserSecretStorage_Encryption_Interface
40
     */
41 15
    public static function getEncryption(LoggerInterface $logger, string $type="dummy", array $options=array()): Tiqr_UserSecretStorage_Encryption_Interface
42
    {
43 15
        $instance = null;
44 15
        $logger->info(sprintf('Using "%s" as UserSecretStorage encryption type', $type));
45 15
        switch ($type) {
46 15
            case "dummy":
47 12
                $instance = new Tiqr_UserSecretStorage_Encryption_Dummy($options);
48 12
                break;
49
            default:
50 3
                if (class_exists($type)) {
51 2
                    $instance = new $type($options);
52
                } else {
53 1
                    throw new RuntimeException(sprintf("Class '%s' not found", $type));
54
                }
55
        }
56
        
57 14
        return $instance;
58
    }
59
}
60