File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change 11
11
* Helper class
12
12
*
13
13
* This class defines various static utility functions that are in use
14
- * throughout the Omnipay system.
14
+ * throughout the Omnipay system.
15
15
*/
16
16
class Helper
17
17
{
@@ -23,6 +23,7 @@ class Helper
23
23
*/
24
24
public static function camelCase ($ str )
25
25
{
26
+ $ str = self ::convertToLowercase ($ str );
26
27
return preg_replace_callback (
27
28
'/_([a-z])/ ' ,
28
29
function ($ match ) {
@@ -32,6 +33,26 @@ function ($match) {
32
33
);
33
34
}
34
35
36
+ /**
37
+ * Convert strings with underscores to be all lowercase before camelCase is preformed.
38
+ *
39
+ * @param string $str The input string
40
+ * @return string The output string
41
+ */
42
+ protected static function convertToLowercase ($ str )
43
+ {
44
+ $ explodedStr = explode ('_ ' , $ str );
45
+
46
+ if (count ($ explodedStr ) > 1 ) {
47
+ foreach ($ explodedStr as $ value ) {
48
+ $ lowercasedStr [] = strtolower ($ value );
49
+ }
50
+ $ str = implode ('_ ' , $ lowercasedStr );
51
+ }
52
+
53
+ return $ str ;
54
+ }
55
+
35
56
/**
36
57
* Validate a card number according to the Luhn algorithm.
37
58
*
Original file line number Diff line number Diff line change @@ -19,6 +19,12 @@ public function testCamelCaseAlreadyCorrect()
19
19
$ this ->assertEquals ('testCase ' , $ result );
20
20
}
21
21
22
+ public function testCamelCaseWithUppercaseValue ()
23
+ {
24
+ $ result = Helper::camelCase ('TEST_CASE ' );
25
+ $ this ->assertEquals ('testCase ' , $ result );
26
+ }
27
+
22
28
public function testValidateLuhnValid ()
23
29
{
24
30
$ result = Helper::validateLuhn ('4111111111111111 ' );
You can’t perform that action at this time.
0 commit comments