Skip to content

Commit

Permalink
Change stringUtil behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentLanglet committed Jul 28, 2024
1 parent 2bf50d4 commit 7c49b94
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Util/StringUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ public static function toSnakeCase(string $string): string

public static function toCamelCase(string $string): string
{
return (new UnicodeString($string))->snake()->camel()->toString();
return (new UnicodeString(static::toSnakeCase($string)))->camel()->toString();
}

public static function toPascalCase(string $string): string
{
return ucfirst((new UnicodeString($string))->camel()->toString());
return ucfirst(static::toCamelCase($string));
}

public static function toKebabCase(string $string): string
Expand Down
1 change: 1 addition & 0 deletions tests/Rules/Variable/VariableName/VariableNameRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function testRulePascalCase(): void
'VariableName.Error:6:8' => 'The var name must use PascalCase; expected UserFoo.',
'VariableName.Error:7:8' => 'The var name must use PascalCase; expected KeyFoo.',
'VariableName.Error:7:16' => 'The var name must use PascalCase; expected UserFoo.',
'VariableName.Error:9:8' => 'The var name must use PascalCase; expected FooBar.',
'VariableName.Error:11:8' => 'The var name must use PascalCase; expected FooBar.',
'VariableName.Error:12:8' => 'The var name must use PascalCase; expected FooBar.',
]);
Expand Down
39 changes: 37 additions & 2 deletions tests/Util/StringUtilTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,19 @@ public static function toSnakeCaseDataProvider(): iterable
yield ['foo-bar', 'foo_bar'];
yield ['FooBar', 'foo_bar'];
yield ['FOOBar', 'foo_bar'];
yield ['foo1bar', 'foo1bar'];
yield ['foo1Bar', 'foo1_bar'];
yield ['foo_bar1', 'foo_bar1'];
yield ['foo1_bar', 'foo1_bar'];
yield ['foo_1bar', 'foo_1bar'];
yield ['foo_1Bar', 'foo_1_bar'];
yield ['foo_bar_1', 'foo_bar_1'];
yield ['foo_1_bar', 'foo_1_bar'];
yield ['foo__bar', 'foo_bar'];
yield ['_foo_bar_', 'foo_bar'];
yield ['foo bar', 'foo_bar'];
yield ['FOO BAR', 'foo_bar'];
yield ['foo#/+bar', 'foo_bar'];
}

/**
Expand All @@ -53,10 +62,18 @@ public static function toCamelCaseDataProvider(): iterable
yield ['foo-bar', 'fooBar'];
yield ['FooBar', 'fooBar'];
yield ['FOOBar', 'fooBar'];
yield ['foo1bar', 'foo1bar'];
yield ['foo1Bar', 'foo1Bar'];
yield ['foo_bar1', 'fooBar1'];
yield ['foo_bar_1', 'fooBar1'];
yield ['foo1_bar', 'foo1Bar'];
yield ['foo_1bar', 'foo1bar'];
yield ['foo_1Bar', 'foo1Bar'];
yield ['foo_1_bar', 'foo1Bar'];
yield ['foo__bar', 'fooBar'];
yield ['_foo_bar_', 'fooBar'];
yield ['foo bar', 'fooBar'];
yield ['FOO BAR', 'fooBar'];
yield ['foo#/+bar', 'fooBar'];
}

/**
Expand All @@ -77,11 +94,20 @@ public static function toPascalCaseDataProvider(): iterable
yield ['foo_bar', 'FooBar'];
yield ['foo-bar', 'FooBar'];
yield ['FooBar', 'FooBar'];
yield ['FOOBar', 'FOOBar'];
yield ['FOOBar', 'FooBar'];
yield ['foo1bar', 'Foo1bar'];
yield ['foo1Bar', 'Foo1Bar'];
yield ['foo_bar1', 'FooBar1'];
yield ['foo1_bar', 'Foo1Bar'];
yield ['foo_1bar', 'Foo1bar'];
yield ['foo_1Bar', 'Foo1Bar'];
yield ['foo_bar_1', 'FooBar1'];
yield ['foo_1_bar', 'Foo1Bar'];
yield ['foo__bar', 'FooBar'];
yield ['_foo_bar_', 'FooBar'];
yield ['foo bar', 'FooBar'];
yield ['FOO BAR', 'FooBar'];
yield ['foo#/+bar', 'FooBar'];
}

/**
Expand All @@ -103,9 +129,18 @@ public static function toKebabCaseDataProvider(): iterable
yield ['foo-bar', 'foo-bar'];
yield ['FooBar', 'foo-bar'];
yield ['FOOBar', 'foo-bar'];
yield ['foo1bar', 'foo1bar'];
yield ['foo1Bar', 'foo1-bar'];
yield ['foo_bar1', 'foo-bar1'];
yield ['foo1_bar', 'foo1-bar'];
yield ['foo_1bar', 'foo-1bar'];
yield ['foo_1Bar', 'foo-1-bar'];
yield ['foo_bar_1', 'foo-bar-1'];
yield ['foo_1_bar', 'foo-1-bar'];
yield ['foo__bar', 'foo-bar'];
yield ['_foo_bar_', 'foo-bar'];
yield ['foo bar', 'foo-bar'];
yield ['FOO BAR', 'foo-bar'];
yield ['foo#/+bar', 'foo-bar'];
}
}

0 comments on commit 7c49b94

Please sign in to comment.