GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Nonce   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 12
c 3
b 0
f 1
dl 0
loc 24
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A generate() 0 15 5
1
<?php
2
/**
3
 * This file is part of the O2System Framework package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author         Steeve Andrian Salim
9
 * @copyright      Copyright (c) Steeve Andrian Salim
10
 */
11
12
// ------------------------------------------------------------------------
13
14
namespace O2System\Security\Generators;
15
16
// ------------------------------------------------------------------------
17
18
use O2System\Security\Encryptions\Algorithm;
19
use O2System\Security\Encryptions\Hmac;
20
21
/**
22
 * Class Nonce
23
 * @package O2System\Security\Authentication\Oauth
24
 */
25
class Nonce
26
{
27
    /**
28
     * Nonce::generate
29
     *
30
     * @param string $algorithm
31
     *
32
     * @return bool|string
33
     */
34
    public static function generate($algorithm = 'HMAC-SHA1')
35
    {
36
        $data = microtime() . mt_rand();
37
        $key = time();
38
39
        if (Algorithm::validate($algorithm)) {
40
            list($function, $algorithm) = Algorithm::map($algorithm);
41
42
            switch ($function) {
43
                case 'HMAC':
44
                    return Hmac::hash($algorithm, $data, $key);
45
                case 'hash_hmac':
46
                    return hash_hmac($algorithm, $data, $key);
47
                case 'openssl':
48
                    return openssl_sign($data, $signature, $key, $algorithm);
49
            }
50
        }
51
    }
52
}