Passed
Push — master ( 1c7137...b5ef5e )
by Pieter van der
03:26 queued 14s
created

Tiqr_OcraService   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 17
c 1
b 0
f 0
dl 0
loc 33
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getOcraService() 0 21 5
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
require_once("Tiqr/OcraService/Abstract.php");
21
22
/**
23
 * Class implementing a factory to retrieve the ocra service to use
24
 *
25
 * @author lineke
26
 */
27
class Tiqr_OcraService
28
{
29
    /**
30
     * Get a ocra service of a certain type (default: 'tiqr')
31
     *
32
     * @param String $type The type of ocra service to create. Supported
33
     *                     types are 'tiqr' or 'oathservice'.
34
     * @param array $options The options to pass to the ocra service
35
     *                       instance.
36
     *
37
     * @return Tiqr_OcraService_Interface
38
     */
39
    public static function getOcraService($type="tiqr", $options=array())
40
    {
41
        switch ($type) {
42
            case "tiqr":
43
                require_once("Tiqr/OcraService/Tiqr.php");
44
                $instance = new Tiqr_OcraService_Tiqr($options);
45
                break;
46
            case "oathserviceclient":
47
                require_once("Tiqr/OcraService/OathServiceClient.php");
48
                $instance = new Tiqr_OcraService_OathServiceClient($options);
49
                break;
50
            default:
51
                if (!isset($type)) {
52
                    throw new Exception('Class name not set');
53
                } elseif (!class_exists($type)) {
54
                    throw new Exception('Class not found: ' . var_export($type, TRUE));
55
                }
56
                $instance = new $type($options);
57
        }
58
59
        return $instance;
60
    }
61
}
62