Cryptography   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 39
ccs 11
cts 11
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateRandomBitsInHex() 0 13 3
A fakeRandomBitsInHex() 0 3 1
1
<?php
2
3
namespace ZoiloMora\ElasticAPM\Helper;
4
5
final class Cryptography
6
{
7
    /**
8
     * @var string
9
     */
10
    private static $fakeRandomBitsInHex;
11
12
    /**
13
     * @param string $fakeRandomBitsInHex
14
     *
15
     * @return void
16
     */
17 12
    public static function fakeRandomBitsInHex($fakeRandomBitsInHex)
18
    {
19 12
        self::$fakeRandomBitsInHex = $fakeRandomBitsInHex;
20 12
    }
21
22
    /**
23
     * Generate random bits in hexadecimal representation
24
     *
25
     * @param int $bits
26
     *
27
     * @return string
28
     *
29
     * @throws \Exception
30
     */
31 35
    public static function generateRandomBitsInHex($bits)
32
    {
33 35
        if (null !== self::$fakeRandomBitsInHex) {
34 5
            return self::$fakeRandomBitsInHex;
35
        }
36
37 34
        $length = $bits / 8;
38 34
        if ($length < 1) {
39 1
            throw new \Exception('Length must be greater than 0.');
40
        }
41
42 33
        return bin2hex(
43 33
            random_bytes($length)
44 33
        );
45
    }
46
}
47