From c4aa6e6ba255dfb7998271f31d3991f1982edca6 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 7 Nov 2011 23:30:43 -0600 Subject: [PATCH] consolidated plural and plural_if into single method. --- laravel/inflector.php | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/laravel/inflector.php b/laravel/inflector.php index 5fa90697..c0c8550a 100644 --- a/laravel/inflector.php +++ b/laravel/inflector.php @@ -114,26 +114,32 @@ class Inflector { 'species', ); - /** - * Get the plural form of a word if the specified count is greater than one. - * - * @param string $value - * @param int $count - * @return string - */ - public static function plural_if($value, $count) - { - return ($count > 1) ? static::plural($value) : $value; - } - /** * Convert a word to its plural form. * + * Optionally, a count argument may be provided. If the count is greater than + * one, the word will be pluralized, otherwise the word will be returned from + * the method unchanged. + * + * + * // Get the plural form of the word "child" + * $children = Inflector::plural('child'); + * + * // Returns "comments" + * $comments = Inflector::plural('comment', 10); + * + * // Returns "comment" + * $comment = Inflector::plural('comment', 1); + * + * * @param string $value + * @param int $count * @return string */ - public static function plural($value) + public static function plural($value, $count = null) { + if ( ! is_null($count) and $count <= 1) return $value; + $irregular = array_flip(static::$irregular); $plural = static::inflect($value, static::$plural_cache, $irregular, static::$plural);