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 1634114

Browse filesBrowse files
raffaelecarellefabpot
authored andcommitted
[String] Add AbstractString::pascal() method
1 parent 446e0d1 commit 1634114
Copy full SHA for 1634114

File tree

4 files changed

+48
-0
lines changed
Filter options

4 files changed

+48
-0
lines changed

‎AbstractString.php

Copy file name to clipboardExpand all lines: 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
/**

‎CHANGELOG.md

Copy file name to clipboardExpand all lines: 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

‎Tests/AbstractAsciiTestCase.php

Copy file name to clipboardExpand all lines: 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
*/

‎Tests/AbstractUnicodeTestCase.php

Copy file name to clipboardExpand all lines: 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.