Passed
Push — master ( f9a115...d52a92 )
by Jonathan
01:25
created

StringFunctions   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 13
c 0
b 0
f 0
dl 0
loc 42
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mysql_concat_ws() 0 6 1
A mysql_concat() 0 7 2
A mysql_format() 0 6 3
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