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

Utils   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 28
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create_random_string() 0 12 2
A pack() 0 3 1
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