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  | 
            ||
| 5 | class UStrObj extends AnyStrObj  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 6 | { | 
            ||
| 7 | const NOT_NORMALIZED = 0;  | 
            ||
| 8 | const NFC = 1;  | 
            ||
| 9 | const NFD = 2;  | 
            ||
| 10 | const NFK = 4;  | 
            ||
| 11 | const NFKC = 5;  | 
            ||
| 12 | const NFKD = 6;  | 
            ||
| 13 | |||
| 14 | protected $chars = [];  | 
            ||
| 15 | protected $uhandler;  | 
            ||
| 16 | protected $normform = self::NOT_NORMALIZED;  | 
            ||
| 17 | |||
| 18 | protected static $spec = [  | 
            ||
| 19 | 2 => ['mask' => 0b00011111, 'start' => 0x80],  | 
            ||
| 20 | 3 => ['mask' => 0b00001111, 'start' => 0x800],  | 
            ||
| 21 | 4 => ['mask' => 0b00000111, 'start' => 0x10000],  | 
            ||
| 22 | 5 => ['mask' => 0b00000011, 'start' => 0x200000],  | 
            ||
| 23 | 6 => ['mask' => 0b00000001, 'start' => 0x4000000],  | 
            ||
| 24 | ];  | 
            ||
| 25 | protected static $winc1umap = [  | 
            ||
| 26 | 0x80 => 0x20AC,  | 
            ||
| 27 | 0x81 => 0xFFFD, // invalid  | 
            ||
| 28 | 0x82 => 0x201A,  | 
            ||
| 29 | 0x83 => 0x0192,  | 
            ||
| 30 | 0x84 => 0x201E,  | 
            ||
| 31 | 0x85 => 0x2026,  | 
            ||
| 32 | 0x86 => 0x2020,  | 
            ||
| 33 | 0x87 => 0x2021,  | 
            ||
| 34 | 0x88 => 0x02C6,  | 
            ||
| 35 | 0x89 => 0x2030,  | 
            ||
| 36 | 0x8A => 0x0160,  | 
            ||
| 37 | 0x8B => 0x2039,  | 
            ||
| 38 | 0x8C => 0x0152,  | 
            ||
| 39 | 0x8D => 0xFFFD, // invalid  | 
            ||
| 40 | 0x8E => 0x017D,  | 
            ||
| 41 | 0x8F => 0xFFFD, // invalid  | 
            ||
| 42 | 0x90 => 0xFFFD, // invalid  | 
            ||
| 43 | 0x91 => 0x2018,  | 
            ||
| 44 | 0x92 => 0x2019,  | 
            ||
| 45 | 0x93 => 0x201C,  | 
            ||
| 46 | 0x94 => 0x201D,  | 
            ||
| 47 | 0x95 => 0x2022,  | 
            ||
| 48 | 0x96 => 0x2013,  | 
            ||
| 49 | 0x97 => 0x2014,  | 
            ||
| 50 | 0x98 => 0x02DC,  | 
            ||
| 51 | 0x99 => 0x2122,  | 
            ||
| 52 | 0x9A => 0x0161,  | 
            ||
| 53 | 0x9B => 0x203A,  | 
            ||
| 54 | 0x9C => 0x0153,  | 
            ||
| 55 | 0x9D => 0xFFFD, // invalid  | 
            ||
| 56 | 0x9E => 0x017E,  | 
            ||
| 57 | 0x9F => 0x0178,  | 
            ||
| 58 | ];  | 
            ||
| 59 | |||
| 60 | View Code Duplication | public function toArray($delim = '', $limit = null)  | 
            |
| 75 | |||
| 76 | /**  | 
            ||
| 77 | * @return string  | 
            ||
| 78 | */  | 
            ||
| 79 | public function charAt($index)  | 
            ||
| 84 | |||
| 85 | /**  | 
            ||
| 86 | * @return int  | 
            ||
| 87 | */  | 
            ||
| 88 | public function charCodeAt($index)  | 
            ||
| 93 | |||
| 94 | /**  | 
            ||
| 95 | *  | 
            ||
| 96 | */  | 
            ||
| 97 | protected static function cpToUtf8Char($cpt)  | 
            ||
| 135 | /**  | 
            ||
| 136 | * @param integer $byte  | 
            ||
| 137 | */  | 
            ||
| 138 | protected static function charLength($byte)  | 
            ||
| 157 | |||
| 158 | private function loadToArray()  | 
            ||
| 236 | |||
| 237 | }  | 
            ||
| 238 |