Completed
Push — master ( 747e00...006ae1 )
by Changwan
03:04
created

Helper::arrayImplode()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 4
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 2.0625
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\Database\Support;
3
4
class Helper
5
{
6
    /**
7
     * @see http://stackoverflow.com/a/1589535
8
     * @param string $text
9
     * @return string
10
     */
11 3
    public static function camelCaseToUnderscore($text)
12
    {
13 3
        return strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $text));
14
    }
15
    
16
    /**
17
     * @param string $glue
18
     * @param string $input
19
     * @param int $multiplier
20
     * @param string $prefix
21
     * @param string $suffix
22
     * @return string
23
     */
24 3
    public static function stringRepeat($glue, $input, $multiplier, $prefix = '', $suffix = '')
25
    {
26 3
        if ($multiplier === 0) {
27
            return $prefix . $suffix;
28
        }
29 3
        return $prefix . $input . str_repeat($glue . $input, $multiplier - 1) . $suffix;
30
    }
31
32
    /**
33
     * @param string $glue
34
     * @param array $input
35
     * @param string $itemPrefix
36
     * @param string $itemSuffix
37
     * @return string
38
     */
39 17
    public static function arrayImplode($glue, $input, $itemPrefix = '', $itemSuffix = '')
40
    {
41 17
        if (!count($input)) {
42
            return '';
43
        }
44 17
        return $itemPrefix . implode($itemSuffix . $glue . $itemPrefix, $input) . $itemSuffix;
45
    }
46
47
    /**
48
     * @param string $name
49
     * @return string
50
     */
51 25
    public static function normalizeName($name)
52
    {
53 25
        return "`" . implode('`.`', explode('.', $name)) . "`";
54
    }
55
}
56