Completed
Push — master ( 6f4d42...4b8ee0 )
by Florent
02:27
created

StringUtil::addPadding()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
eloc 2
nc 2
nop 4
1
<?php
2
3
/*
4
 * The MIT License (MIT)
5
 *
6
 * Copyright (c) 2014-2016 Spomky-Labs
7
 *
8
 * This software may be modified and distributed under the terms
9
 * of the MIT license.  See the LICENSE file for details.
10
 */
11
12
namespace Jose\Util;
13
14
/**
15
 * Class String.
16
 */
17
final class StringUtil
18
{
19
    /**
20
     * @param int $size
21
     * 
22
     * @return string
23
     */
24
    public static function generateRandomBytes($size)
25
    {
26
        if (function_exists('random_bytes')) {
27
            return random_bytes($size);
28
        } elseif (function_exists('openssl_random_pseudo_bytes')) {
29
            return openssl_random_pseudo_bytes($size);
30
        } elseif (function_exists('mcrypt_create_iv')) {
31
            return mcrypt_create_iv($size);
32
        }
33
        throw new \RuntimeException('Unable to create random bytes.');
34
    }
35
}
36