NoncerAbstract   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 93.75%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 74
ccs 15
cts 16
cp 0.9375
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setLength() 0 4 1
A getLength() 0 4 1
hash() 0 1 ?
A generate() 0 5 1
A getLastNonce() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
namespace Acquia\Rest;
4
5
abstract class NoncerAbstract implements NoncerInterface
6
{
7
    const DEFAULT_LENGTH = 24;
8
9
    /**
10
     * @var string
11
     */
12
    protected $lastNonce = '';
13
14
    /**
15
     * @var int
16
     */
17
    protected $length;
18
19
    /**
20
     * @param integer $length
21
     */
22 63
    public function __construct($length = self::DEFAULT_LENGTH)
23
    {
24 63
        $this->length = $length;
25 63
    }
26
27
    /**
28
     * @param int $length
29
     */
30 30
    public function setLength($length)
31
    {
32 30
        $this->length = $length;
33 30
    }
34
35
    /**
36
     * @return integer
37
     */
38 3
    public function getLength()
39
    {
40 3
        return $this->length;
41
    }
42
43
    /**
44
     * Generates the nonce.
45
     *
46
     * @return string
47
     */
48
    abstract protected function hash();
49
50
    /**
51
     * Generates and stores a nonce.
52
     *
53
     * @return string
54
     */
55 57
    public function generate()
56
    {
57 57
        $this->lastNonce = $this->hash();
58 57
        return $this->lastNonce;
59
    }
60
61
    /**
62
     * @return string
63
     */
64 48
    public function getLastNonce()
65
    {
66 48
        return $this->lastNonce;
67
    }
68
69
    /**
70
     * Generates and returns a nonce.
71
     *
72
     * @see NoncerAbstract::generate()
73
     */
74 3
    public function __toString()
75
    {
76 3
        return $this->generate();
77
    }
78
}
79