Skip to content

Commit 1635924

Browse files
committed
Merge pull request #62 from Nicole8164/uppercase-fix
Adding support for getter/setter created for values made up of all caps and underscores.
2 parents d9b3d3e + 8985ad6 commit 1635924

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/Omnipay/Common/Helper.php

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Helper class
1212
*
1313
* This class defines various static utility functions that are in use
14-
* throughout the Omnipay system.
14+
* throughout the Omnipay system.
1515
*/
1616
class Helper
1717
{
@@ -23,6 +23,7 @@ class Helper
2323
*/
2424
public static function camelCase($str)
2525
{
26+
$str = self::convertToLowercase($str);
2627
return preg_replace_callback(
2728
'/_([a-z])/',
2829
function ($match) {
@@ -32,6 +33,26 @@ function ($match) {
3233
);
3334
}
3435

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+
3556
/**
3657
* Validate a card number according to the Luhn algorithm.
3758
*

tests/Omnipay/Common/HelperTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ public function testCamelCaseAlreadyCorrect()
1919
$this->assertEquals('testCase', $result);
2020
}
2121

22+
public function testCamelCaseWithUppercaseValue()
23+
{
24+
$result = Helper::camelCase('TEST_CASE');
25+
$this->assertEquals('testCase', $result);
26+
}
27+
2228
public function testValidateLuhnValid()
2329
{
2430
$result = Helper::validateLuhn('4111111111111111');

0 commit comments

Comments
 (0)