Skip to content

Commit 3d34286

Browse files
committed
Tweaked inflection to stop trying to turn beta into betum. Updated inflection tests to make sure that plural words don't change when pluralized and singular words don't change when singularized
1 parent 7d44822 commit 3d34286

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

src/Strings.php

+17-3
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ function depluralize(string $sWord) : string {
2222
->withSingularRules(
2323
new Ruleset(
2424
new Transformations(),
25-
new Patterns(),
26-
new Substitutions(new Substitution(new Word('data'), new Word('datum')))
25+
new Patterns(
26+
new Pattern('beta')
27+
),
28+
new Substitutions(
29+
new Substitution(new Word('data'), new Word('datum'))
30+
)
2731
)
2832
)
2933
->build();
@@ -36,6 +40,16 @@ function depluralize(string $sWord) : string {
3640
*/
3741
function pluralize(string $sWord): string {
3842
// https://www.doctrine-project.org/projects/doctrine-inflector/en/2.0/index.html
39-
$oInflector = InflectorFactory::create()->build();
43+
$oInflector = InflectorFactory::create()
44+
->withPluralRules(
45+
new Ruleset(
46+
new Transformations(),
47+
new Patterns(
48+
new Pattern('geese')
49+
),
50+
new Substitutions()
51+
)
52+
)
53+
->build();
4054
return $oInflector->pluralize($sWord);
4155
}

tests/DepluralizeTest.php

+6-7
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,17 @@ public function setUp():void {
2626
];
2727
}
2828

29-
public function testDepluralize(): void
30-
{
29+
public function testDepluralize(): void {
3130
foreach($this->aWords as $sPlural => $sSingular) {
32-
$this->assertEquals($sSingular, depluralize($sPlural));
31+
self::assertEquals($sSingular, depluralize($sPlural));
32+
self::assertEquals($sSingular, depluralize($sSingular));
3333
}
3434
}
3535

36-
public function testPluralize(): void
37-
{
36+
public function testPluralize(): void {
3837
foreach ($this->aWords as $sPlural => $sSingular) {
39-
$this->assertEquals($sPlural, pluralize($sSingular));
38+
self::assertEquals($sPlural, pluralize($sSingular));
39+
self::assertEquals($sPlural, pluralize($sPlural));
4040
}
4141
}
42-
4342
}

0 commit comments

Comments
 (0)