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

Tiqr_UserStorage_File   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 44.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 28
ccs 4
cts 9
cp 0.4444
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _deleteUser() 0 7 2
A __construct() 0 4 1
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/UserStorage/GenericStore.php';
24
25
/**
26
 * This user storage implementation implements a simple user 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_UserStorage_File extends Tiqr_UserStorage_GenericStore
33
{
34
    use FileTrait;
35
36
    protected $path;
37
38
    /**
39
     * Create an instance
40
     * @param array $config
41
     * @param LoggerInterface $logger
42
     */
43 4
    public function __construct($config, LoggerInterface $logger)
44
    {
45 4
        parent::__construct($config, $logger);
46 4
        $this->path = $config["path"];
47 4
    }
48
49
    /**
50
     * Delete user data (un-enroll).
51
     * @param String $userId
52
     */
53
    protected function _deleteUser($userId)
54
    {
55
        $filename = $this->getPath().$userId.".json";
56
        if (file_exists($filename)) {
57
            unlink($filename);
58
        } else {
59
            $this->logger->error('Unable to remove the user from user storage (file storage)');
60
        }
61
    }
62
}
63