Tiqr_OcraService::getOcraService()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 12
ccs 8
cts 8
cp 1
rs 10
cc 4
nc 6
nop 3
crap 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-2012 SURFnet BV
18
 */
19
20
use Psr\Log\LoggerInterface;
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
     * @throws Exception An exception if an unknown orca service type is requested.
39
     */
40 11
    public static function getOcraService(string $type="tiqr", array $options=array(), LoggerInterface $logger=null)
41
    {
42 11
        if (!$logger)
43 1
            $logger=new \Psr\Log\NullLogger();
44
45
        switch ($type) {
46 11
            case "tiqr":
47 9
                return new Tiqr_OcraService_Tiqr($options, $logger);
48 2
            case "oathserviceclient":
49 1
                return new Tiqr_OcraService_OathServiceClient($options, $logger);
50
        }
51 1
        throw new RuntimeException(sprintf('Unable to create a OcraService instance of type: %s', $type));
52
    }
53
}
54