Passed
Push — master ( 12216b...17b30e )
by Amin
02:35
created

Helper::appendSlash()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 6
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
16
class Helper
17
{
18
    /**
19
     * round a number to nearest even number
20
     *
21
     * @param float $number
22
     * @return int
23
     */
24
    public static function roundToEven(float $number): int
25
    {
26
        return (($number = intval($number)) % 2 == 0) ? $number : $number + 1;
27
    }
28
29
    /**
30
     * @param int $length
31
     * @return bool|string
32
     */
33
    public static function randomString($length = 10)
34
    {
35
        $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
36
        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

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