Passed
Pull Request — master (#5)
by Aleksandr
02:21
created

extract_after()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 1
b 0
f 0
cc 2
nc 1
nop 2
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
61
if (!function_exists('extract_after')) {
62
    /**
63
     * Get string content after.
64
     *
65
     * @param string $string
66
     * @param string $char
67
     *
68
     * @return string
69
     */
70
    function extract_after(string $string, string $char = ':'): string
71
    {
72
        $title = strtok($string, $char) ?: '';
73
        $value = substr($string, strlen($title));
74
75
        return trim(ltrim($value, $char));
76
    }
77
}
78