Passed
Push — develop ( 22eefe...e65dcd )
by Pieter van der
06:04
created

Tiqr_UserSecretStorage_File   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 1
b 0
f 0
dl 0
loc 40
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setUserSecret() 0 5 1
A getUserSecret() 0 8 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-2012 SURFnet BV
18
 */
19
20 1
require_once 'Tiqr/UserStorage/File.php';
21
22
/**
23
 * This user storage implementation implements a simple user's secret storage using json files.
24
 * This is mostly for demonstration and development purposes. In a production environment
25
 * please supply your own implementation that hosts the data in your user database OR
26
 * in a secure (e.g. hardware encrypted) storage.
27
 * @author ivo
28
 */
29
class Tiqr_UserSecretStorage_File extends Tiqr_UserStorage_File implements Tiqr_UserSecretStorage_Interface
30
{
31
    /**
32
     * Create an instance
33
     *
34
     * @param array $config
35
     */
36 1
    public function __construct($config, $secretconfig = array())
37
    {
38 1
        $this->_path = $config["path"];
39 1
    }
40
41
    /**
42
     * Get the user's secret
43
     *
44
     * @param String $userId
45
     *
46
     * @return String The user's secret
47
     */
48 1
    public function getUserSecret($userId)
49
    {
50 1
        if ($data = $this->_loadUser($userId)) {
51 1
            if (isset($data["secret"])) {
52 1
                return $data["secret"];
53
            }
54
        }
55 1
        return NULL;
56
    }
57
58
    /**
59
     * Store a secret for a user
60
     *
61
     * @param String $userId
62
     * @param String $secret
63
     */
64 1
    public function setUserSecret($userId, $secret)
65
    {
66 1
        $data = $this->_loadUser($userId, false);
67 1
        $data["secret"] = $secret;
68 1
        $this->_saveUser($userId, $data);
0 ignored issues
show
Bug introduced by
$data of type false is incompatible with the type array expected by parameter $data of Tiqr_UserStorage_File::_saveUser(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

68
        $this->_saveUser($userId, /** @scrutinizer ignore-type */ $data);
Loading history...
69 1
    }
70
}
71