diff --git a/src/Pluralizer.php b/src/Pluralizer.php index 3621588..f51d185 100644 --- a/src/Pluralizer.php +++ b/src/Pluralizer.php @@ -19,7 +19,7 @@ class Pluralizer private $word; - public function __construct(string $word) + public function __construct(Word $word) { $this->word = $word; } @@ -27,31 +27,35 @@ public function __construct(string $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() diff --git a/src/Word.php b/src/Word.php index daa9bb4..d9af2db 100644 --- a/src/Word.php +++ b/src/Word.php @@ -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()