-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #192 from homersimpsons/fix/column-name-starting-w…
…ith-digit Column starting with a digit (#184): Add test
- Loading branch information
Showing
8 changed files
with
54 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace TheCodingMachine\TDBM\Utils; | ||
|
||
class StringUtils | ||
{ | ||
public static function getValidVariableName(string $variableName): string | ||
{ | ||
return preg_replace_callback('/^(\d+)/', static function (array $match) { | ||
$f = new \NumberFormatter('en', \NumberFormatter::SPELLOUT); | ||
$number = $f->format((int) $match[0]); | ||
return preg_replace('/[^a-z]+/i', '_', $number); | ||
}, $variableName); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Test\Utils; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use TheCodingMachine\TDBM\Utils\StringUtils; | ||
|
||
class StringUtilsTest extends TestCase | ||
{ | ||
public function testGetValidVariableName(): void | ||
{ | ||
$this->assertEquals('threed_view', StringUtils::getValidVariableName('3d_view')); | ||
$this->assertEquals('one_thousand_four_hundred_thirty_two_var_1432_test', StringUtils::getValidVariableName('1432_var_1432_test')); | ||
} | ||
} |