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

IdentifierGenerator::generateUniqueIdentifier()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 4

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 2
cts 2
cp 1
rs 9.7666
c 0
b 0
f 0
cc 4
nc 4
nop 1
crap 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