Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e23a0d2

Browse filesBrowse files
committed
feature #58545 [String] Add AbstractString::pascal() method (raffaelecarelle)
This PR was squashed before being merged into the 7.3 branch. Discussion ---------- [String] Add `AbstractString::pascal()` method | Q | A | ------------- | --- | Branch? | 7.3 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | | License | MIT Introduce a new `pascal()` method to the `AbstractString` class to transform strings to PascalCase. Accompany the implementation with relevant test cases to ensure correctness and immutability. Update the changelog to document this new method. Commits ------- 3cb12a0 [String] Add `AbstractString::pascal()` method
2 parents fc65c8f + 3cb12a0 commit e23a0d2
Copy full SHA for e23a0d2

File tree

4 files changed

+48
-0
lines changed
Filter options

4 files changed

+48
-0
lines changed

‎src/Symfony/Component/String/AbstractString.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/String/AbstractString.php
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ public function kebab(): static
438438
return $this->snake()->replace('_', '-');
439439
}
440440

441+
public function pascal(): static
442+
{
443+
return $this->camel()->title();
444+
}
445+
441446
abstract public function splice(string $replacement, int $start = 0, ?int $length = null): static;
442447

443448
/**

‎src/Symfony/Component/String/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/String/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
7.3
5+
---
6+
7+
* Add the `AbstractString::pascal()` method
8+
49
7.2
510
---
611

‎src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/String/Tests/AbstractAsciiTestCase.php
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,33 @@ public static function provideKebab(): array
11181118
];
11191119
}
11201120

1121+
/**
1122+
* @dataProvider providePascal
1123+
*/
1124+
public function testPascal(string $expectedString, string $origin)
1125+
{
1126+
$instance = static::createFromString($origin)->pascal();
1127+
1128+
$this->assertEquals(static::createFromString($expectedString), $instance);
1129+
$this->assertNotSame($origin, $instance, 'Strings should be immutable');
1130+
}
1131+
1132+
public static function providePascal(): array
1133+
{
1134+
return [
1135+
['', ''],
1136+
['XY', 'x_y'],
1137+
['XuYo', 'xu_yo'],
1138+
['SymfonyIsGreat', 'symfony_is_great'],
1139+
['Symfony5IsGreat', 'symfony_5_is_great'],
1140+
['SymfonyIsGreat', 'Symfony is great'],
1141+
['SYMFONYISGREAT', 'SYMFONY_IS_GREAT'],
1142+
['SymfonyIsAGreatFramework', 'Symfony is a great framework'],
1143+
['SymfonyIsGREAT', '*Symfony* is GREAT!!'],
1144+
['SYMFONY', 'SYMFONY'],
1145+
];
1146+
}
1147+
11211148
/**
11221149
* @dataProvider provideStartsWith
11231150
*/

‎src/Symfony/Component/String/Tests/AbstractUnicodeTestCase.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/String/Tests/AbstractUnicodeTestCase.php
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,17 @@ public static function provideCamel()
655655
);
656656
}
657657

658+
public static function providePascal(): array
659+
{
660+
return array_merge(
661+
parent::providePascal(),
662+
[
663+
['SymfonyIstÄußerstCool', 'symfonyIstÄußerstCool'],
664+
['SymfonyWithEmojis', 'Symfony with 😃 emojis'],
665+
]
666+
);
667+
}
668+
658669
public static function provideSnake()
659670
{
660671
return array_merge(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.