Passed
Push — develop ( 55d6dd...809f15 )
by Pieter van der
06:46
created

Tiqr_UserStorage   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 60%

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 6
eloc 21
c 2
b 0
f 1
dl 0
loc 45
ccs 12
cts 20
cp 0.6
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B getStorage() 0 25 6
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 Ivo Jansch <[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
/**
21
 * Class implementing a factory to retrieve user data.
22
 *
23
 * @author ivo
24
 */
25
class Tiqr_UserStorage
26
{
27
    /**
28
     * Get a storage of a certain type (default: 'file')
29
     *
30
     * @param String $type The type of storage to create. Supported
31
     *                     types are 'file', 'ldap' or the full class name.
32
     * @param array $options The options to pass to the storage
33
     *                       instance. See the documentation
34
     *                       in the UserStorage/ subdirectory for
35
     *                       options per type.
36
     * @param array $secretoptions  The options to pass to the secret storage
37
     *                              instance. See the documentation
38
     *                              in the UserSecretStorage/ subdirectory for
39
     *                              options per type.
40
     *
41
     * @return Tiqr_UserStorage_Interface
42
     *
43
     * @throws Exception
44
     */
45 3
    public static function getStorage($type="file", $options=array(), $secretoptions=array())
46
    {
47 3
        switch ($type) {
48 3
            case "file":
49 1
                require_once("Tiqr/UserStorage/File.php");
50 1
                $instance = new Tiqr_UserStorage_File($options, $secretoptions);
51 1
                break;
52 2
            case "ldap":
53
                require_once("Tiqr/UserStorage/Ldap.php");
54
                $instance = new Tiqr_UserStorage_Ldap($options, $secretoptions);
55
                break;
56 2
            case "pdo":
57 2
                require_once("Tiqr/UserStorage/Pdo.php");
58 2
                $instance = new Tiqr_UserStorage_Pdo($options, $secretoptions);
59 2
                break;
60
            default: 
61
                if (!isset($type)) {
62
                    throw new Exception('Class name not set');
63
                } elseif (!class_exists($type)) {
64
                    throw new Exception('Class not found: ' . var_export($type, TRUE));
65
                }
66
                $instance = new $type($options, $secretoptions);
67
        }
68
69 3
        return $instance;
70
    }
71
}
72