Skip to content

Commit

Permalink
Cleaning up Inflector::singular and Inflector::plural
Browse files Browse the repository at this point in the history
  • Loading branch information
Woody Gilk committed Sep 1, 2010
1 parent ed89d26 commit fca3d5c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions classes/kohana/inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static function uncountable($str)
* [!!] Special inflections are defined in `config/inflector.php`.
*
* @param string word to singularize
* @param integer number of things
* @param integer count of thing
* @return string
* @uses Inflector::uncountable
*/
Expand All @@ -72,9 +72,9 @@ public static function singular($str, $count = NULL)
// Remove garbage
$str = strtolower(trim($str));

if (is_string($count))
if ($count !== NULL)
{
// Convert to integer when using a digit string
// Force an integer value, so that === 0 works
$count = (int) $count;
}

Expand Down Expand Up @@ -108,10 +108,12 @@ public static function singular($str, $count = NULL)
}
elseif (preg_match('/[^aeiou]ies$/', $str))
{
// Replace "ies" with "y"
$str = substr($str, 0, -3).'y';
}
elseif (substr($str, -1) === 's' AND substr($str, -2) !== 'ss')
{
// Remove singular "s"
$str = substr($str, 0, -1);
}

Expand All @@ -132,7 +134,8 @@ public static function singular($str, $count = NULL)
*
* [!!] Special inflections are defined in `config/inflector.php`.
*
* @param string word to pluralize
* @param string word to pluralize
* @param integer count of thing
* @return string
* @uses Inflector::uncountable
*/
Expand All @@ -141,6 +144,11 @@ public static function plural($str, $count = NULL)
// Remove garbage
$str = strtolower(trim($str));

if ($count !== NULL)
{
$count

This comment has been minimized.

Copy link
@joelpittet

joelpittet Sep 1, 2010

Contributor

this doesn't look quite right and gives me a segfault(mac php 5.3.1 does this for syntax errors).

This comment has been minimized.

Copy link
@shadowhand

shadowhand Sep 1, 2010

Contributor

Whoa, thanks Joel! Fixed by 105723e

}

if (is_string($count))
{
// Convert to integer when using a digit string
Expand Down

0 comments on commit fca3d5c

Please sign in to comment.