Skip to content

Commit cb374e5

Browse files
authored
Merge pull request #6 from kynx/preserve-internal-capitalisation
Preserve internal capitalisation in camelCase and PascalCase words
2 parents db84f18 + bd73ad5 commit cb374e5

2 files changed

Lines changed: 15 additions & 13 deletions

File tree

src/WordCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function convert(string $string): string
4242
*/
4343
private function toCamel(array $parts): string
4444
{
45-
$ucFirst = array_map(fn (string $part): string => ucfirst(strtolower($part)), $parts);
45+
$ucFirst = array_map(fn (string $part): string => ucfirst($part), $parts);
4646
$previous = '';
4747
foreach ($ucFirst as $i => $part) {
4848
if ($i === 0) {
@@ -70,7 +70,7 @@ private function toLowerSnake(array $parts): string
7070
*/
7171
private function toPascal(array $parts): string
7272
{
73-
$ucFirst = array_map(fn (string $part): string => ucfirst(strtolower($part)), $parts);
73+
$ucFirst = array_map(fn (string $part): string => ucfirst($part), $parts);
7474
$previous = '';
7575
foreach ($ucFirst as $i => $part) {
7676
if (strlen($previous) === 1 && strlen($part) === 1) {

test/WordCaseTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ public function testConvert(WordCase $case, string $string, string $expected): v
2424
public function stringProvider(): array
2525
{
2626
return [
27-
'empty' => [WordCase::LowerSnake, '', ''],
28-
'just_spaces' => [WordCase::LowerSnake, " ", ''],
29-
'trim' => [WordCase::LowerSnake, " foo ", 'foo'],
30-
'numbers' => [WordCase::LowerSnake, "foo123 bar", 'foo123_bar'],
31-
'underscore' => [WordCase::LowerSnake, "one two_three", "one_two_three"],
32-
'camel' => [WordCase::Camel, 'FOO bAR', 'fooBar'],
33-
'camelAbbr' => [WordCase::Camel, 'a b foo', 'abFoo'],
34-
'lower_snake' => [WordCase::LowerSnake, 'FOO BAR', 'foo_bar'],
35-
'Pascal' => [WordCase::Pascal, 'fOO bAR', 'FooBar'],
36-
'PascalAbbr' => [WordCase::Pascal, 'a b foo', 'AbFoo'],
37-
'UPPER_SNAKE' => [WordCase::UpperSnake, 'foo bar', 'FOO_BAR'],
27+
'empty' => [WordCase::LowerSnake, '', ''],
28+
'just_spaces' => [WordCase::LowerSnake, " ", ''],
29+
'trim' => [WordCase::LowerSnake, " foo ", 'foo'],
30+
'numbers' => [WordCase::LowerSnake, "foo123 bar", 'foo123_bar'],
31+
'underscore' => [WordCase::LowerSnake, "one two_three", "one_two_three"],
32+
'camel' => [WordCase::Camel, 'Foo bar', 'fooBar'],
33+
'camelAbbr' => [WordCase::Camel, 'a b foo', 'abFoo'],
34+
'camelPreserve' => [WordCase::Camel, 'FooBar', 'fooBar'],
35+
'lower_snake' => [WordCase::LowerSnake, 'FOO BAR', 'foo_bar'],
36+
'Pascal' => [WordCase::Pascal, 'foo bar', 'FooBar'],
37+
'PascalAbbr' => [WordCase::Pascal, 'a b foo', 'AbFoo'],
38+
'PascalPreserve' => [WordCase::Pascal, 'fooBar', 'FooBar'],
39+
'UPPER_SNAKE' => [WordCase::UpperSnake, 'foo bar', 'FOO_BAR'],
3840
];
3941
}
4042
}

0 commit comments

Comments
 (0)