Skip to content

Commit

Permalink
Merge pull request #6 from kynx/preserve-internal-capitalisation
Browse files Browse the repository at this point in the history
Preserve internal capitalisation in camelCase and PascalCase words
  • Loading branch information
kynx authored Oct 14, 2022
2 parents db84f18 + bd73ad5 commit cb374e5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/WordCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function convert(string $string): string
*/
private function toCamel(array $parts): string
{
$ucFirst = array_map(fn (string $part): string => ucfirst(strtolower($part)), $parts);
$ucFirst = array_map(fn (string $part): string => ucfirst($part), $parts);
$previous = '';
foreach ($ucFirst as $i => $part) {
if ($i === 0) {
Expand Down Expand Up @@ -70,7 +70,7 @@ private function toLowerSnake(array $parts): string
*/
private function toPascal(array $parts): string
{
$ucFirst = array_map(fn (string $part): string => ucfirst(strtolower($part)), $parts);
$ucFirst = array_map(fn (string $part): string => ucfirst($part), $parts);
$previous = '';
foreach ($ucFirst as $i => $part) {
if (strlen($previous) === 1 && strlen($part) === 1) {
Expand Down
24 changes: 13 additions & 11 deletions test/WordCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,19 @@ public function testConvert(WordCase $case, string $string, string $expected): v
public function stringProvider(): array
{
return [
'empty' => [WordCase::LowerSnake, '', ''],
'just_spaces' => [WordCase::LowerSnake, " ", ''],
'trim' => [WordCase::LowerSnake, " foo ", 'foo'],
'numbers' => [WordCase::LowerSnake, "foo123 bar", 'foo123_bar'],
'underscore' => [WordCase::LowerSnake, "one two_three", "one_two_three"],
'camel' => [WordCase::Camel, 'FOO bAR', 'fooBar'],
'camelAbbr' => [WordCase::Camel, 'a b foo', 'abFoo'],
'lower_snake' => [WordCase::LowerSnake, 'FOO BAR', 'foo_bar'],
'Pascal' => [WordCase::Pascal, 'fOO bAR', 'FooBar'],
'PascalAbbr' => [WordCase::Pascal, 'a b foo', 'AbFoo'],
'UPPER_SNAKE' => [WordCase::UpperSnake, 'foo bar', 'FOO_BAR'],
'empty' => [WordCase::LowerSnake, '', ''],
'just_spaces' => [WordCase::LowerSnake, " ", ''],
'trim' => [WordCase::LowerSnake, " foo ", 'foo'],
'numbers' => [WordCase::LowerSnake, "foo123 bar", 'foo123_bar'],
'underscore' => [WordCase::LowerSnake, "one two_three", "one_two_three"],
'camel' => [WordCase::Camel, 'Foo bar', 'fooBar'],
'camelAbbr' => [WordCase::Camel, 'a b foo', 'abFoo'],
'camelPreserve' => [WordCase::Camel, 'FooBar', 'fooBar'],
'lower_snake' => [WordCase::LowerSnake, 'FOO BAR', 'foo_bar'],
'Pascal' => [WordCase::Pascal, 'foo bar', 'FooBar'],
'PascalAbbr' => [WordCase::Pascal, 'a b foo', 'AbFoo'],
'PascalPreserve' => [WordCase::Pascal, 'fooBar', 'FooBar'],
'UPPER_SNAKE' => [WordCase::UpperSnake, 'foo bar', 'FOO_BAR'],
];
}
}

0 comments on commit cb374e5

Please sign in to comment.