Completed
Pull Request — master (#526)
by Michael
01:57
created

StringFunctions::mb_ucfirst()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 8
ccs 7
cts 7
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
class StringFunctions
4
{
5
	/**
6
	 * @param string $string
7
	 * @return string
8
	 */
9 1
	private static function mb_ucfirst($string)
10
	{
11 1
		$strlen = mb_strlen($string);
12 1
		$substr = mb_substr($string, 0, 1);
13 1
		$substr2 = mb_substr($string, 1, $strlen - 1);
14 1
		$upstring = mb_strtoupper($substr);
15 1
		$ustring = $upstring . $substr2;
16 1
		return $ustring;
17
	}
18
19
	/**
20
	 * Formats a string to be used as a username.
21
	 * @param $username
22
	 * @return string
23
	 */
24 1
	public static function formatAsUsername($username)
25
	{
26 1
		$uname = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $username);
27 1
		$uname = self::mb_ucfirst($uname);
28 1
		$uname = mb_ereg_replace("[ ]+", "_", $uname);
29 1
		$uname = mb_ereg_replace("[_]+$", "", $uname);
30 1
		return $uname;
31
	}
32
33
	/**
34
	 * Formats a string to be used as an email (specifically strips whitespace
35
	 * from the beginning/end of the Email, as well as immediately before/after
36
	 * the @ in the Email).
37
	 * @param $email
38
	 * @return string
39
	 */
40 1
	public static function formatAsEmail($email)
41
	{
42 1
		$newemail = mb_ereg_replace("^[ \t]+|[ \t]+$", "", $email);
43 1
		$newemail = mb_ereg_replace("[ \t]+@", "@", $newemail);
44 1
		$newemail = mb_ereg_replace("@[ \t]+", "@", $newemail);
45 1
		return $newemail;
46
	}
47
48
}
49