Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php  | 
            ||
| 18 | class Inflector { | 
            ||
| 19 | |||
| 20 | protected static $plural = array(  | 
            ||
| 21 | '/(quiz)$/i' => "$1zes",  | 
            ||
| 22 | '/^(ox)$/i' => "$1en",  | 
            ||
| 23 | '/([m|l])ouse$/i' => "$1ice",  | 
            ||
| 24 | '/(matr|vert|ind)ix|ex$/i' => "$1ices",  | 
            ||
| 25 | '/(x|ch|ss|sh)$/i' => "$1es",  | 
            ||
| 26 | '/([^aeiouy]|qu)y$/i' => "$1ies",  | 
            ||
| 27 | '/(hive)$/i' => "$1s",  | 
            ||
| 28 | '/(?:([^f])fe|([lr])f)$/i' => "$1$2ves",  | 
            ||
| 29 | '/(shea|lea|loa|thie)f$/i' => "$1ves",  | 
            ||
| 30 | '/sis$/i' => "ses",  | 
            ||
| 31 | '/([ti])um$/i' => "$1a",  | 
            ||
| 32 | '/(tomat|potat|ech|her|vet)o$/i'=> "$1oes",  | 
            ||
| 33 | '/(bu)s$/i' => "$1ses",  | 
            ||
| 34 | '/(alias)$/i' => "$1es",  | 
            ||
| 35 | '/(ax|test)is$/i' => "$1es",  | 
            ||
| 36 | '/(us)$/i' => "$1es",  | 
            ||
| 37 | '/s$/i' => "s",  | 
            ||
| 38 | '/$/' => "s"  | 
            ||
| 39 | );  | 
            ||
| 40 | |||
| 41 | protected static $singular = array(  | 
            ||
| 42 | '/(quiz)zes$/i' => "$1",  | 
            ||
| 43 | '/(matr)ices$/i' => "$1ix",  | 
            ||
| 44 | '/(vert|ind)ices$/i' => "$1ex",  | 
            ||
| 45 | '/^(ox)en$/i' => "$1",  | 
            ||
| 46 | '/(alias)es$/i' => "$1",  | 
            ||
| 47 | '/(cris|ax|test)es$/i' => "$1is",  | 
            ||
| 48 | '/(shoe)s$/i' => "$1",  | 
            ||
| 49 | '/(o)es$/i' => "$1",  | 
            ||
| 50 | '/(bus)es$/i' => "$1",  | 
            ||
| 51 | '/([m|l])ice$/i' => "$1ouse",  | 
            ||
| 52 | '/(x|ch|ss|sh)es$/i' => "$1",  | 
            ||
| 53 | '/(m)ovies$/i' => "$1ovie",  | 
            ||
| 54 | '/(s)eries$/i' => "$1eries",  | 
            ||
| 55 | '/([^aeiouy]|qu)ies$/i' => "$1y",  | 
            ||
| 56 | '/([lr])ves$/i' => "$1f",  | 
            ||
| 57 | '/(tive)s$/i' => "$1",  | 
            ||
| 58 | '/(hive)s$/i' => "$1",  | 
            ||
| 59 | '/(li|wi|kni)ves$/i' => "$1fe",  | 
            ||
| 60 | '/(shea|loa|lea|thie)ves$/i'=> "$1f",  | 
            ||
| 61 | '/(^analy)ses$/i' => "$1sis",  | 
            ||
| 62 | '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => "$1$2sis",  | 
            ||
| 63 | '/([ti])a$/i' => "$1um",  | 
            ||
| 64 | '/(n)ews$/i' => "$1ews",  | 
            ||
| 65 | '/(h|bl)ouses$/i' => "$1ouse",  | 
            ||
| 66 | '/(corpse)s$/i' => "$1",  | 
            ||
| 67 | '/(us)es$/i' => "$1",  | 
            ||
| 68 | '/s$/i' => ""  | 
            ||
| 69 | );  | 
            ||
| 70 | |||
| 71 | protected static $irregular = array(  | 
            ||
| 72 | 'move' => 'moves',  | 
            ||
| 73 | 'foot' => 'feet',  | 
            ||
| 74 | 'goose' => 'geese',  | 
            ||
| 75 | 'sex' => 'sexes',  | 
            ||
| 76 | 'child' => 'children',  | 
            ||
| 77 | 'man' => 'men',  | 
            ||
| 78 | 'tooth' => 'teeth',  | 
            ||
| 79 | 'person' => 'people'  | 
            ||
| 80 | );  | 
            ||
| 81 | |||
| 82 | protected static $uncountable = array(  | 
            ||
| 83 | 'sheep',  | 
            ||
| 84 | 'fish',  | 
            ||
| 85 | 'deer',  | 
            ||
| 86 | 'series',  | 
            ||
| 87 | 'species',  | 
            ||
| 88 | 'money',  | 
            ||
| 89 | 'rice',  | 
            ||
| 90 | 'information',  | 
            ||
| 91 | 'equipment'  | 
            ||
| 92 | );  | 
            ||
| 93 | |||
| 94 | // TODO: cache results to speed up subsequent use?  | 
            ||
| 95 | View Code Duplication | 	public static function pluralise( $string ) { | 
            |
| 121 | |||
| 122 | // TODO: cache results to speed up subsequent use?  | 
            ||
| 123 | View Code Duplication | 	public static function singularise( $string ) { | 
            |
| 145 | |||
| 146 | }  | 
            ||
| 147 | |||
| 148 | // EOF  |