Strings   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

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

2 Methods

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