Skip to content

Commit

Permalink
Change Pluralizer to accept and return Word objects
Browse files Browse the repository at this point in the history
  • Loading branch information
DivineOmega committed Feb 12, 2018
1 parent 2b9dcd3 commit d577725
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions src/Pluralizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,43 @@ class Pluralizer

private $word;

public function __construct(string $word)
public function __construct(Word $word)
{
$this->word = $word;
}

public function pluralize()
{
if ($this->isUncountable()) {
return $this->word;
return new Word($this->word);
}

foreach($this->irregular as $singular => $plural) {
if ($singular==$this->word) {
return $plural;
return new Word($plural);
}
}

return Inflector::pluralize($this->word);
$plural = Inflector::pluralize((string) $this->word);

return new Word($plural);
}

public function singularize()
{
if ($this->isUncountable()) {
return $this->word;
return new Word($this->word);
}

foreach($this->irregular as $singular => $plural) {
if ($plural==$this->word) {
return $singular;
return new Word($singular);
}
}

return Inflector::singularize($this->word);
$singular = Inflector::singularize((string) $this->word);

return new Word($singular);
}

private function isUncountable()
Expand Down
4 changes: 2 additions & 2 deletions src/Word.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public function syllables()

public function plural()
{
return (new Pluralizer($this->word))->pluralize();
return (new Pluralizer($this))->pluralize();
}

public function singular()
{
return (new Pluralizer($this->word))->singularize();
return (new Pluralizer($this))->singularize();
}

public function offensive()
Expand Down

0 comments on commit d577725

Please sign in to comment.