DaveChild\TextStatistics\Pluralise::getPlural PHP Method

getPlural() public static method

Get the plural of the word passed in.
public static getPlural ( string $string ) : string
$string string Word to pluralise
return string Pluralised word
    public static function getPlural($string)
    {
        // save some time in the case that singular and plural are the same
        if (in_array(strtolower($string), self::$uncountable)) {
            return $string;
        }
        // check to see if already plural and irregular
        foreach (self::$irregular as $pattern => $result) {
            $_pattern = '/' . $result . '$/i';
            if (preg_match($_pattern, $string)) {
                return $string;
            }
        }
        // check for irregular singular forms
        foreach (self::$irregular as $pattern => $result) {
            $pattern = '/' . $pattern . '$/i';
            if (preg_match($pattern, $string)) {
                return preg_replace($pattern, $result, $string);
            }
        }
        // check for matches using regular expressions
        foreach (self::$plural as $pattern => $result) {
            if (preg_match($pattern, $string)) {
                return preg_replace($pattern, $result, $string);
            }
        }
        // No pattern match. Add an "s".
        return $string . 's';
    }