Completed
Push — master ( 2bc6ba...1ab902 )
by Francesco
09:17
created

SecretGenerator::generateRandomSecret()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2.0625
1
<?php
2
3
/*
4
 * This file is part of the MesCryptoBundle package.
5
 *
6
 * (c) Francesco Cartenì <http://www.multimediaexperiencestudio.it/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Mes\Security\CryptoBundle\Utils;
13
14
/**
15
 * Class SecretGenerator.
16
 */
17
class SecretGenerator
18
{
19
    /**
20
     * Generates a random secret.
21
     *
22
     * @return string The randomly generated secret
23
     */
24 5
    public function generateRandomSecret()
25
    {
26 5
        if (function_exists('openssl_random_pseudo_bytes')) {
27 5
            return hash('sha1', openssl_random_pseudo_bytes(23));
28
        }
29
30
        return hash('sha1', uniqid(mt_rand(), true));
31
    }
32
}
33