Passed
Push — main ( 992366...dd7998 )
by Dylan
02:08
created

Utils::pack()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Lifeboat\SDK\Utils;
4
5
class Utils {
6
7
    /**
8
     * @param int $length
9
     * @param string $characters
10
     * @return string
11
     */
12
    public static function create_random_string(
13
        int $length = 24,
14
        string $characters = '0123456789abcdefghijklmnopqrstuvwxyz'
15
    ): string {
16
        $charactersLength = strlen($characters);
17
        $randomString = '';
18
19
        for ($i = 0; $i < $length; $i++) {
20
            $randomString .= $characters[rand(0, $charactersLength - 1)];
21
        }
22
23
        return $randomString;
24
    }
25
26
    /**
27
     * @param string $str
28
     * @return string
29
     */
30
    public static function pack(string $str): string
31
    {
32
        return rtrim(strtr(base64_encode(pack('H*',  hash('sha256', $str))), '+/', '-_'), '=');
33
    }
34
}
35