Utils   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

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

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\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