Completed
Pull Request — master (#987)
by
unknown
02:10
created

IdentifierGenerator   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 21
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A generateUniqueIdentifier() 0 15 4
1
<?php declare(strict_types=1);
2
3
namespace League\OAuth2\Server\IdentifierGenerator;
4
5
use Error;
6
use Exception;
7
use League\OAuth2\Server\Exception\OAuthServerException;
8
use TypeError;
9
10
class IdentifierGenerator implements IdentifierGeneratorInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15 3
    public function generateUniqueIdentifier($length = 40)
16
    {
17
        try {
18 3
            return bin2hex(random_bytes($length));
19
            // @codeCoverageIgnoreStart
20
        } catch (TypeError $e) {
21
            throw OAuthServerException::serverError('An unexpected error has occurred', $e);
22
        } catch (Error $e) {
23
            throw OAuthServerException::serverError('An unexpected error has occurred', $e);
24
        } catch (Exception $e) {
25
            // If you get this message, the CSPRNG failed hard.
26
            throw OAuthServerException::serverError('Could not generate a random string', $e);
27
        }
28
        // @codeCoverageIgnoreEnd
29
    }
30
}
31