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

Tiqr_UserSecretStorage_File   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 17
c 1
b 0
f 0
dl 0
loc 51
ccs 13
cts 15
cp 0.8667
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A setUserSecret() 0 5 1
A getUserSecret() 0 9 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
use Psr\Log\LoggerInterface;
21
22 1
require_once 'Tiqr/UserStorage/FileTrait.php';
23 1
require_once 'Tiqr/UserSecretStorage/UserSecretStorageTrait.php';
24
25
/**
26
 * This user storage implementation implements a simple user's secret storage using json files.
27
 * This is mostly for demonstration and development purposes. In a production environment
28
 * please supply your own implementation that hosts the data in your user database OR
29
 * in a secure (e.g. hardware encrypted) storage.
30
 * @author ivo
31
 */
32
class Tiqr_UserSecretStorage_File implements Tiqr_UserSecretStorage_Interface
33
{
34
    use UserSecretStorageTrait;
35
    use FileTrait;
36
37
    private $userSecretStorage;
0 ignored issues
show
introduced by
The private property $userSecretStorage is not used, and could be removed.
Loading history...
38
39
    private $logger;
40
41
    private $path;
42
43 5
    public function __construct(
44
        Tiqr_UserSecretStorage_Encryption_Interface $encryption,
45
        string $path,
46
        LoggerInterface $logger
47
    ) {
48
        // See UserSecretStorageTrait
49 5
        $this->encryption = $encryption;
50 5
        $this->logger = $logger;
51 5
        $this->path = $path;
52 5
    }
53
54
    /**
55
     * Get the user's secret
56
     *
57
     * @param String $userId
58
     *
59
     * @return String The user's secret
60
     */
61 1
    private function getUserSecret($userId)
0 ignored issues
show
Unused Code introduced by
The method getUserSecret() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
62
    {
63 1
        if ($data = $this->_loadUser($userId)) {
64 1
            if (isset($data["secret"])) {
65 1
                return $data["secret"];
66
            }
67
        }
68
        $this->logger->error('Unable to retrieve the secret (user not found). In user secret storage (file)');
69
        return NULL;
70
    }
71
72
    /**
73
     * Store a secret for a user
74
     *
75
     * @param String $userId
76
     * @param String $secret
77
     */
78 1
    private function setUserSecret($userId, $secret)
0 ignored issues
show
Unused Code introduced by
The method setUserSecret() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
79
    {
80 1
        $data = $this->_loadUser($userId, false);
81 1
        $data["secret"] = $secret;
82 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_UserSecretStorage_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

82
        $this->_saveUser($userId, /** @scrutinizer ignore-type */ $data);
Loading history...
83 1
    }
84
}
85