Passed
Pull Request — master (#5)
by Aleksandr
03:12
created

glue_commands()   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
eloc 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
if (!function_exists('extract_bssid')) {
4
    /**
5
     * Extracting bssid from passed string.
6
     *
7
     * @param string $string
8
     * @param int    $matchColumn
9
     *
10
     * @return array
11
     */
12
    function extract_bssid(string $string, int $matchColumn): array
13
    {
14
        $extractedBssid = [];
15
16
        preg_match_all(
17
            '/(\w{2}:\w{2}:\w{2}:\w{2}:\w{2}:\w{2})/',
18
            $string,
19
            $extractedBssid
20
        );
21
22
        return array_unique(array_column($extractedBssid, $matchColumn));
23
    }
24
}
25
26
if (!function_exists('to_hex')) {
27
    /**
28
     * Converting string to hex.
29
     *
30
     * @param string $string
31
     *
32
     * @return string
33
     */
34
    function to_hex(string $string): string
35
    {
36
        $len = strlen($string);
37
        $hex = '';
38
39
        for ($i = 0; $i < $len; $i++) {
40
            $hex .= substr('0'.dechex(ord($string[$i])), -2);
41
        }
42
43
        return strtoupper($hex);
44
    }
45
}
46
47
if (!function_exists('glue_commands')) {
48
    /**
49
     * Glue commands.
50
     *
51
     * @param string ...$commands
52
     *
53
     * @return string
54
     */
55
    function glue_commands(string ...$commands): string
56
    {
57
        return implode(' && ', $commands);
58
    }
59
}
60