Tiqr_DeviceStorage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 13
c 2
b 0
f 0
dl 0
loc 32
ccs 12
cts 12
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getStorage() 0 17 4
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
use Psr\Log\LoggerInterface;
22
23
/**
24
 * A utility class to create an instance of a specific type of storage that 
25
 * can retrieve deviceTokens.
26
 * @author ivo
27
 */
28
class Tiqr_DeviceStorage
29
{
30
    /**
31
     * Return a storage instance of a certain type.
32
     * Supported types are dummy: stores the device token 
33
     * @param String $type The type of storage to return. Supported are:
34
     *                     - dummy: treats a notificationToken as a deviceToken
35
     *                     - tokenexchange: uses a tokenexchange service to 
36
     *                       exchange notificationTokens for deviceTokens. 
37
     * @param array $options Options for the device storage. See the
38
     *                       documentation in DeviceStorage/ for specific 
39
     *                       config options per type.
40
     * @param LoggerInterface $logger
41
     * @throws Exception An exception if an unknown storage is requested.
42
     */
43 11
    public static function getStorage(string $type="dummy", Array $options=array(), LoggerInterface $logger=null)
44
    {
45 11
        if (!$logger)
46 1
            $logger=new \Psr\Log\NullLogger();
47
48
        switch ($type) {
49 11
            case "dummy":
50 9
                $instance = new Tiqr_DeviceStorage_Dummy($options, $logger);
51 9
                $instance->init();
52 9
                return $instance;
53 2
            case "tokenexchange":
54 1
                $instance = new Tiqr_DeviceStorage_TokenExchange($options, $logger);
55 1
                $instance->init();
56 1
                return $instance;
57
        }
58
59 1
        throw new RuntimeException(sprintf('Unable to create a DeviceStorage instance of type: %s', $type));
60
    }
61
}
62