Completed
Push — master ( bda266...ce7873 )
by Aleksandr
15s queued 10s
created

to_hex()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 1
b 0
f 0
cc 2
nc 2
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