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

Helper   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 10
cts 12
cp 0.8333
rs 10
c 0
b 0
f 0
wmc 6
lcom 0
cbo 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A camelCaseToUnderscore() 0 4 1
A stringRepeat() 0 7 2
A arrayImplode() 0 7 2
A normalizeName() 0 4 1
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