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

Tiqr_DeviceStorage::getStorage()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 16
ccs 13
cts 13
cp 1
rs 9.8666
cc 3
nc 3
nop 3
crap 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 Ivo Jansch <[email protected]>
12
 * 
13
 * @package tiqr
14
 *
15
 * @license New BSD License - See LICENSE file for details.
16
 *
17
 * @copyright (C) 2010-2011 SURFnet BV
18
 */
19
20
21
/**
22
 * @internal includes
23
 */
24 1
require_once("Tiqr/DeviceStorage/Abstract.php");
25
26
use Psr\Log\LoggerInterface;
27
28
/**
29
 * A utility class to create an instance of a specific type of storage that 
30
 * can retrieve deviceTokens.
31
 * @author ivo
32
 */
33
class Tiqr_DeviceStorage
34
{
35
    /**
36
     * Return a storage instance of a certain type.
37
     * Supported types are dummy: stores the device token 
38
     * @param String $type The type of storage to return. Supported are:
39
     *                     - dummy: treats a notificationToken as a deviceToken
40
     *                     - tokenexchange: uses a tokenexchange service to 
41
     *                       exchange notificationTokens for deviceTokens. 
42
     * @param array $options Options for the device storage. See the
43
     *                       documentation in DeviceStorage/ for specific 
44
     *                       config options per type.
45
     * @param LoggerInterface $logger
46
     * @throws Exception An exception if an unknown storage is requested.
47
     */
48 7
    public static function getStorage($type="dummy", $options=array(), LoggerInterface $logger)
49
    {
50 7
        switch ($type) {
51 7
            case "dummy":
52 5
                require_once("Tiqr/DeviceStorage/Dummy.php");
53 5
                $instance = new Tiqr_DeviceStorage_Dummy($options, $logger);
54 5
                $instance->init();
55 5
                return $instance;
56 2
            case "tokenexchange":
57 1
                require_once("Tiqr/DeviceStorage/TokenExchange.php");
58 1
                $instance = new Tiqr_DeviceStorage_TokenExchange($options, $logger);
59 1
                $instance->init();
60 1
                return $instance;
61
        }
62
63 1
        throw new RuntimeException(sprintf('Unable to create a DeviceStorage instance of type: %s', $type));
64
    }
65
}
66