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

Helper::stringRepeat()   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 5
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 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