Completed
Push — master ( fe4c2e...b05117 )
by Michael
12s
created

Basic   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 5
c 1
b 1
f 0
lcom 1
cbo 3
dl 0
loc 45
rs 10
ccs 10
cts 10
cp 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getSigning() 0 4 1
A getVerifying() 0 4 1
A create() 0 7 2
A kill() 0 4 1
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
namespace Xmf\Key;
13
14
use Xmf\Random;
15
16
/**
17
 * Xmf\Key\StorageInterface
18
 *
19
 * load a database table
20
 *
21
 * @category  Xmf\Key\Basic
22
 * @package   Xmf
23
 * @author    Richard Griffith <[email protected]>
24
 * @copyright 2016 XOOPS Project (http://xoops.org)
25
 * @license   GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
26
 * @version   Release: 1.0
27
 * @link      http://xoops.org
28
 */
29
class Basic extends KeyAbstract
30
{
31
    /**
32
     * get key for use in signing
33
     *
34
     * @return string verifying key, false on error
35
     */
36 1
    public function getSigning()
37
    {
38 1
        return (string) $this->storage->fetch($this->name);
39
    }
40
41
    /**
42
     * get key for use in verifying
43
     *
44
     * @return string verifying key, false on error
45
     */
46 1
    public function getVerifying()
47
    {
48 1
        return (string) $this->storage->fetch($this->name);
49
    }
50
51
    /**
52
     * create the key and store it for use
53
     *
54
     * @return boolean true if key was created and stored, otherwise false
55
     */
56 1
    public function create()
57
    {
58 1
        if (!$this->storage->exists($this->name)) {
59 1
            return $this->storage->save($this->name, Random::generateKey());
60
        }
61 1
        return false;
62
    }
63
64
    /**
65
     * delete the key
66
     *
67
     * @return boolean true if key was deleted, otherwise false
68
     */
69 1
    public function kill()
70
    {
71 1
        return $this->storage->delete($this->name);
72
    }
73
}
74