Passed
Push — master ( 3ee3fe...b14545 )
by Amin
04:48
created

Helper::makeDir()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
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
class Helper
15
{
16
    /**
17
     * round a number to nearest even number
18
     *
19
     * @param float $number
20
     * @return int
21
     */
22
    public static function roundToEven(float $number): int
23
    {
24
        return (($number = intval($number)) % 2 == 0) ? $number : $number + 1;
25
    }
26
27
28
    /**
29
     * @param $dirname
30
     */
31
    public static function makeDir($dirname): void
32
    {
33
        if (!is_dir($dirname)) {
34
            mkdir($dirname, 0777, true);
35
        }
36
    }
37
38
    public static function randomString($length = 10)
39
    {
40
        $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
41
        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

41
        return substr(str_shuffle(str_repeat($chars, /** @scrutinizer ignore-type */ ceil($length / strlen($chars)))), 1, $length);
Loading history...
42
43
    }
44
}