Passed
Push — master ( b9a200...e484b3 )
by Jonathan
10:09
created

StringFunctions::mysql_soundex()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Vectorface\MySQLite\MySQL;
4
5
/**
6
 * Provides String Manipulation MySQL compatibility functions for SQLite.
7
 *
8
 * http://dev.mysql.com/doc/refman/5.7/en/string-functions.html
9
 */
10
trait StringFunctions
11
{
12
13
     /**
14
     * Concat - Return a concatenated string of all function arguments provided
15
     * @return string $str concatenated string
16
     */
17
    public static function mysql_concat()
18
    {
19
        $str = '';
20
        foreach (func_get_args() as $arg) {
21
            $str .= $arg;
22
        }
23
        return $str;
24
    }
25
26
    /**
27
     * Concat_ws - Return a concatenated string of all function arguments provided
28
     * it will use the first argument as the separator
29
     * @return string $str concatenated string with separator
30
     */
31
    public static function mysql_concat_ws()
32
    {
33
        $args = func_get_args();
34
        $seperator = array_shift($args);
35
        $str = implode($seperator, $args);
36
        return $str;
37
    }
38
39
40
    /**
41
     * Format - Return a formated number string based on the arguments provided
42
     * Ignoring the functionality of a third argument, locale
43
     * https://dev.mysql.com/doc/refman/8.0/en/string-functions.html#function_format
44
     * @return string $str formatted as per arg
45
     */
46
    public static function mysql_format()
47
    {
48
        $args = func_get_args();
49
        $number = isset($args[0]) ? $args[0] : 0.0;
50
        $decimals = isset($args[1]) ? $args[1] : 0;
51
        return number_format($number, $decimals);
52
    }
53
54
    /**
55
     * Get the soundex value of a given string
56
     */
57
    public static function mysql_soundex(string $str): string
58
    {
59
        return soundex($str);
60
    }
61
}
62