Completed
Push — master ( 6247dd...e88f06 )
by Peter
07:34
created

Strings   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 22.22%

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 49
ccs 2
cts 9
cp 0.2222
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A decamelize() 0 4 1
A camelize() 0 11 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: peter
5
 * Date: 15.06.18
6
 * Time: 18:49
7
 */
8
9
namespace Maslosoft\Manganel\Helpers;
10
11
12
class Strings
13
{
14
	/**
15
	 *
16
	 * @param string $input
17
	 * @param string $separator
18
	 * @return string
19
	 */
20 1
	public static function decamelize($input, $separator = '-')
21
	{
22 1
		return ltrim(strtolower(preg_replace('/[A-Z]/', "$separator$0", $input)), $separator);
23
	}
24
25
	/**
26
	 * Will return CamelCased value from `input`.
27
	 *
28
	 * Example:
29
	 *
30
	 * ```
31
	 * camelize('my-html-id');
32
	 * ```
33
	 *
34
	 * Will return `MyHtmlId`.
35
	 *
36
	 * Can also accept different separator or make first letter lower case:
37
	 *
38
	 * ```
39
	 * camelize('\My\Php\ClassName', '\\', true);
40
	 * ```
41
	 *
42
	 * Will return `myPhpClassName`. This might be useful for generating HTML id's
43
	 * from PHP class names.
44
	 *
45
	 * @param string $input
46
	 * @param string $separator
47
	 * @return string
48
	 */
49
	public static function camelize($input, $separator = '-', $lcFirst = false)
50
	{
51
		assert(is_string($input));
52
		$spaced = str_replace($separator, ' ', $input);
53
		$result = str_replace(' ', '', ucwords($spaced));
54
		if ($lcFirst)
55
		{
56
			return lcfirst($result);
57
		}
58
		return $result;
59
	}
60
}