Completed
Pull Request — master (#2)
by Milos
04:36
created

OpenSslRandomGenerator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
wmc 3
lcom 0
cbo 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A get() 0 9 3
1
<?php
2
3
/*
4
 * This file is part of the tmilos/jose-jwt package.
5
 *
6
 * (c) Milos Tomic <[email protected]>
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Tmilos\JoseJwt\Random;
13
14
use Tmilos\JoseJwt\Error\JoseJwtException;
15
16
class OpenSslRandomGenerator implements RandomGenerator
17
{
18
    /**
19
     * @param int $bytesLength
20
     *
21
     * @return string
22
     */
23
    public function get($bytesLength)
24
    {
25
        $result = openssl_random_pseudo_bytes($bytesLength, $strong);
26
        if (false === $result || false === $strong) {
27
            throw new JoseJwtException('Unable to generate strong random sequence');
28
        }
29
30
        return $result;
31
    }
32
}
33