Skip to content

Commit

Permalink
Replacing icanboogie/inflector with doctrine/inflector because the la…
Browse files Browse the repository at this point in the history
…tter allows for adjusting rules
  • Loading branch information
enobrev committed Aug 27, 2020
1 parent 0bb2801 commit 7d44822
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 35 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"php": ">=7.2",
"ext-json": "*",
"adbario/php-dot-notation": "~2.2",
"icanboogie/inflector": "^2.0",
"doctrine/inflector": "^2.0",
"laminas/laminas-diactoros": "^2.2",
"laminas/laminas-httphandlerrunner": "^1.1",
"monolog/monolog": "^2.0"
Expand Down
87 changes: 56 additions & 31 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 24 additions & 3 deletions src/Strings.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
<?php
namespace Enobrev;

use ICanBoogie\Inflector;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\Inflector\Rules\Pattern;
use Doctrine\Inflector\Rules\Patterns;
use Doctrine\Inflector\Rules\Ruleset;
use Doctrine\Inflector\Rules\Substitution;
use Doctrine\Inflector\Rules\Substitutions;
use Doctrine\Inflector\Rules\Transformation;
use Doctrine\Inflector\Rules\Transformations;
use Doctrine\Inflector\Rules\Word;


/**
* @param string $sWord
* @return string
*/
function depluralize(string $sWord) : string {
return Inflector::get()->singularize($sWord);
// https://www.doctrine-project.org/projects/doctrine-inflector/en/2.0/index.html
$oInflector = InflectorFactory::create()
->withSingularRules(
new Ruleset(
new Transformations(),
new Patterns(),
new Substitutions(new Substitution(new Word('data'), new Word('datum')))
)
)
->build();
return $oInflector->singularize($sWord);
}

/**
* @param string $sWord
* @return string
*/
function pluralize(string $sWord): string {
return Inflector::get()->pluralize($sWord);
// https://www.doctrine-project.org/projects/doctrine-inflector/en/2.0/index.html
$oInflector = InflectorFactory::create()->build();
return $oInflector->pluralize($sWord);
}
1 change: 1 addition & 0 deletions tests/DepluralizeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public function setUp():void {
'addresses' => 'address',
'cities' => 'city',
'data' => 'datum',
'betas' => 'beta',
'fish' => 'fish',
'geese' => 'goose',
'languages' => 'language',
Expand Down

0 comments on commit 7d44822

Please sign in to comment.