Passed
Push — master ( 8e077c...e6cc46 )
by Amin
03:50
created

Utilities::randomString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
<?php
2
3
/**
4
 * This file is part of the PHP-FFmpeg-video-streaming package.
5
 *
6
 * (c) Amin Yazdanpanah <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Streaming;
13
14
15
class Utilities
16
{
17
    /**
18
     * round a number to nearest even number
19
     *
20
     * @param float $number
21
     * @return int
22
     */
23
    public static function roundToEven(float $number): int
24
    {
25
        return (($number = intval($number)) % 2 == 0) ? $number : $number + 1;
26
    }
27
28
    /**
29
     * @param int $length
30
     * @return bool|string
31
     */
32
    public static function randomString($length = 10)
33
    {
34
        $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
35
        return substr(str_shuffle(str_repeat($chars, ceil($length / strlen($chars)))), 1, $length);
0 ignored issues
show
Bug introduced by
ceil($length / strlen($chars)) of type double is incompatible with the type integer expected by parameter $multiplier of str_repeat(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
        return substr(str_shuffle(str_repeat($chars, /** @scrutinizer ignore-type */ ceil($length / strlen($chars)))), 1, $length);
Loading history...
36
    }
37
38
    /**
39
     * @param $word
40
     * @return bool|string
41
     */
42
    public static function appendSlash(string $word)
43
    {
44
        return $word ? rtrim($word, '/') . '/' : '';
45
    }
46
}