Completed
Push — master ( 1e376d...b0060a )
by Changwan
05:50
created

Helper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 43
ccs 8
cts 10
cp 0.8
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A camelCaseToUnderscore() 0 4 1
A stringRepeat() 0 7 2
A arrayImplode() 0 7 2
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 2
    public static function stringRepeat($glue, $input, $multiplier, $prefix = '', $suffix = '')
25
    {
26 2
        if ($multiplier === 0) {
27
            return $prefix . $suffix;
28
        }
29 2
        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 12
    public static function arrayImplode($glue, $input, $itemPrefix = '', $itemSuffix = '')
40
    {
41 12
        if (!count($input)) {
42
            return '';
43
        }
44 12
        return $itemPrefix . implode($itemSuffix . $glue . $itemPrefix, $input) . $itemSuffix;
45
    }
46
}
47