GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — master ( 6b69a8...372506 )
by Joni
03:38
created

RandomCEK::cekForEncryption()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 10
ccs 6
cts 7
cp 0.8571
rs 10
c 1
b 0
f 0
cc 3
nc 3
nop 1
crap 3.0261
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Sop\JWX\JWE\KeyAlgorithm\Feature;
6
7
/**
8
 * Trait for key algorithms employing random CEK generation.
9
 */
10
trait RandomCEK
11
{
12
    /**
13
     * Generate a random content encryption key.
14
     *
15
     * @param int $length Key length in bytes
16
     *
17
     * @throws \RuntimeException
18
     */
19 3
    public function cekForEncryption(int $length): string
20
    {
21 3
        if ($length < 1) {
22 1
            throw new \InvalidArgumentException('Length must be greater than 0.');
23
        }
24 2
        $ret = openssl_random_pseudo_bytes($length);
25 2
        if (false === $ret) {
26
            throw new \RuntimeException('openssl_random_pseudo_bytes() failed.');
27
        }
28 2
        return $ret;
29
    }
30
}
31