Passed
Push — master ( 35fb8a...2dccb2 )
by Pieter van der
05:32 queued 14s
created

Tiqr_UserSecretStorage_File   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Test Coverage

Coverage 82.35%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 19
c 1
b 0
f 0
dl 0
loc 56
ccs 14
cts 17
cp 0.8235
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A setUserSecret() 0 8 2
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
     * @throws Exception
61
     */
62 1
    private function getUserSecret(string $userId): string
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...
63
    {
64 1
        if ($data = $this->_loadUser($userId)) {
65 1
            if (isset($data["secret"])) {
66 1
                return $data["secret"];
67
            }
68
        }
69
        $this->logger->error(sprintf('User or user secret not found in secret storage (file) for user "%s"', $userId));
70
        throw new RuntimeException('User or user secret not found in secret storage (File)');
71
    }
72
73
    /**
74
     * Store a secret for a user
75
     *
76
     * @param String $userId
77
     * @param String $secret
78
     * @throws Exception
79
     */
80 1
    private function setUserSecret(string $userId, string $secret): void
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...
81
    {
82 1
        $data=array();
83 1
        if ($this->_userExists($userId)) {
84
            $data = $this->_loadUser($userId);
85
        }
86 1
        $data["secret"] = $secret;
87 1
        $this->_saveUser($userId, $data);
88 1
    }
89
}
90