| Conditions | 13 |
| Paths | 113 |
| Total Lines | 125 |
| Code Lines | 96 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 114 | protected function segment( $input, $encoding = null ) { |
||
| 115 | |||
| 116 | if ( !$input ) { |
||
| 117 | return array(); |
||
| 118 | } |
||
| 119 | |||
| 120 | if ( !$encoding ) { |
||
| 121 | $encoding = mb_detect_encoding( $input ); |
||
| 122 | } |
||
| 123 | |||
| 124 | if ( $encoding !== 'UTF-8' ) { |
||
| 125 | $input = mb_convert_encoding( $input, 'UTF-8', $encoding ); |
||
| 126 | } |
||
| 127 | |||
| 128 | $result = array(); |
||
| 129 | $seg = array( "B3", "B2", "B1" ); |
||
| 130 | |||
| 131 | $ctype = array( "O", "O", "O" ); |
||
| 132 | $o = $this->mb_string_to_array_( $input ); |
||
| 133 | |||
| 134 | for ( $i = 0; $i<count($o); ++$i ) { |
||
| 135 | $seg[] = $o[$i]; |
||
| 136 | $ctype[] = $this->ctype_( $o[$i] ); |
||
| 137 | } |
||
| 138 | |||
| 139 | $seg[] = "E1"; |
||
| 140 | $seg[] = "E2"; |
||
| 141 | $seg[] = "E3"; |
||
| 142 | $ctype[] = "O"; |
||
| 143 | $ctype[] = "O"; |
||
| 144 | $ctype[] = "O"; |
||
| 145 | $word = $seg[3]; |
||
| 146 | $p1 = "U"; |
||
| 147 | $p2 = "U"; |
||
| 148 | $p3 = "U"; |
||
| 149 | |||
| 150 | for($i = 4; $i<count($seg)-3; ++$i){ |
||
| 151 | $score = self::$model["BIAS"]; |
||
| 152 | $w1 = $seg[$i-3]; |
||
| 153 | $w2 = $seg[$i-2]; |
||
| 154 | $w3 = $seg[$i-1]; |
||
| 155 | $w4 = $seg[$i]; |
||
| 156 | $w5 = $seg[$i+1]; |
||
| 157 | $w6 = $seg[$i+2]; |
||
| 158 | $c1 = $ctype[$i-3]; |
||
| 159 | $c2 = $ctype[$i-2]; |
||
| 160 | $c3 = $ctype[$i-1]; |
||
| 161 | $c4 = $ctype[$i]; |
||
| 162 | $c5 = $ctype[$i+1]; |
||
| 163 | $c6 = $ctype[$i+2]; |
||
| 164 | $score += $this->ts_(@self::$model["UP1"][$p1]); |
||
| 165 | $score += $this->ts_(@self::$model["UP2"][$p2]); |
||
| 166 | $score += $this->ts_(@self::$model["UP3"][$p3]); |
||
| 167 | $score += $this->ts_(@self::$model["BP1"][$p1 . $p2]); |
||
| 168 | $score += $this->ts_(@self::$model["BP2"][$p2 . $p3]); |
||
| 169 | $score += $this->ts_(@self::$model["UW1"][$w1]); |
||
| 170 | $score += $this->ts_(@self::$model["UW2"][$w2]); |
||
| 171 | $score += $this->ts_(@self::$model["UW3"][$w3]); |
||
| 172 | $score += $this->ts_(@self::$model["UW4"][$w4]); |
||
| 173 | $score += $this->ts_(@self::$model["UW5"][$w5]); |
||
| 174 | $score += $this->ts_(@self::$model["UW6"][$w6]); |
||
| 175 | $score += $this->ts_(@self::$model["BW1"][$w2 . $w3]); |
||
| 176 | $score += $this->ts_(@self::$model["BW2"][$w3 . $w4]); |
||
| 177 | $score += $this->ts_(@self::$model["BW3"][$w4 . $w5]); |
||
| 178 | $score += $this->ts_(@self::$model["TW1"][$w1 . $w2 . $w3]); |
||
| 179 | $score += $this->ts_(@self::$model["TW2"][$w2 . $w3 . $w4]); |
||
| 180 | $score += $this->ts_(@self::$model["TW3"][$w3 . $w4 . $w5]); |
||
| 181 | $score += $this->ts_(@self::$model["TW4"][$w4 . $w5 . $w6]); |
||
| 182 | $score += $this->ts_(@self::$model["UC1"][$c1]); |
||
| 183 | $score += $this->ts_(@self::$model["UC2"][$c2]); |
||
| 184 | $score += $this->ts_(@self::$model["UC3"][$c3]); |
||
| 185 | $score += $this->ts_(@self::$model["UC4"][$c4]); |
||
| 186 | $score += $this->ts_(@self::$model["UC5"][$c5]); |
||
| 187 | $score += $this->ts_(@self::$model["UC6"][$c6]); |
||
| 188 | $score += $this->ts_(@self::$model["BC1"][$c2 . $c3]); |
||
| 189 | $score += $this->ts_(@self::$model["BC2"][$c3 . $c4]); |
||
| 190 | $score += $this->ts_(@self::$model["BC3"][$c4 . $c5]); |
||
| 191 | $score += $this->ts_(@self::$model["TC1"][$c1 . $c2 . $c3]); |
||
| 192 | $score += $this->ts_(@self::$model["TC2"][$c2 . $c3 . $c4]); |
||
| 193 | $score += $this->ts_(@self::$model["TC3"][$c3 . $c4 . $c5]); |
||
| 194 | $score += $this->ts_(@self::$model["TC4"][$c4 . $c5 . $c6]); |
||
| 195 | // $score += $this->ts_(@self::$model["TC5"][$c4 . $c5 . $c6]); |
||
| 196 | $score += $this->ts_(@self::$model["UQ1"][$p1 . $c1]); |
||
| 197 | $score += $this->ts_(@self::$model["UQ2"][$p2 . $c2]); |
||
| 198 | $score += $this->ts_(@self::$model["UQ1"][$p3 . $c3]); |
||
| 199 | $score += $this->ts_(@self::$model["BQ1"][$p2 . $c2 . $c3]); |
||
| 200 | $score += $this->ts_(@self::$model["BQ2"][$p2 . $c3 . $c4]); |
||
| 201 | $score += $this->ts_(@self::$model["BQ3"][$p3 . $c2 . $c3]); |
||
| 202 | $score += $this->ts_(@self::$model["BQ4"][$p3 . $c3 . $c4]); |
||
| 203 | $score += $this->ts_(@self::$model["TQ1"][$p2 . $c1 . $c2 . $c3]); |
||
| 204 | $score += $this->ts_(@self::$model["TQ2"][$p2 . $c2 . $c3 . $c4]); |
||
| 205 | $score += $this->ts_(@self::$model["TQ3"][$p3 . $c1 . $c2 . $c3]); |
||
| 206 | $score += $this->ts_(@self::$model["TQ4"][$p3 . $c2 . $c3 . $c4]); |
||
| 207 | |||
| 208 | $p = "O"; |
||
| 209 | |||
| 210 | if ( $score > 0 ) { |
||
| 211 | |||
| 212 | if ( $word !== '' && $word !== ' ' ) { |
||
| 213 | $result[] = $word; |
||
| 214 | } |
||
| 215 | |||
| 216 | $word = ""; |
||
| 217 | $p = "B"; |
||
| 218 | } |
||
| 219 | |||
| 220 | $p1 = $p2; |
||
| 221 | $p2 = $p3; |
||
| 222 | $p3 = $p; |
||
| 223 | |||
| 224 | if ( $seg[$i] !== '' && $seg[$i] !== ' ' ) { |
||
| 225 | $word .= $seg[$i]; |
||
| 226 | } |
||
| 227 | } |
||
| 228 | |||
| 229 | $result[] = $word; |
||
| 230 | |||
| 231 | if ( $encoding !== 'UTF-8') { |
||
| 232 | foreach( $result as &$str ) { |
||
| 233 | $str = mb_convert_encoding( $str, $encoding, 'UTF-8' ); |
||
| 234 | } |
||
| 235 | } |
||
| 236 | |||
| 237 | return $result; |
||
| 238 | } |
||
| 239 | |||
| 268 |
This check marks private properties in classes that are never used. Those properties can be removed.