Conditions | 10 |
Paths | 10 |
Total Lines | 43 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 17.2354 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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 |
||
10219 | 10 | public static function strrev(string $str, string $encoding = 'UTF-8'): string |
|
10220 | { |
||
10221 | 10 | if ($str === '') { |
|
10222 | 4 | return ''; |
|
10223 | } |
||
10224 | |||
10225 | // init |
||
10226 | 8 | $reversed = ''; |
|
10227 | |||
10228 | 8 | $str = self::emoji_encode($str, true); |
|
10229 | |||
10230 | 8 | if ($encoding === 'UTF-8') { |
|
10231 | 8 | if (self::$SUPPORT['intl'] === true) { |
|
10232 | // try "grapheme" first: https://stackoverflow.com/questions/17496493/strrev-dosent-support-utf-8 |
||
10233 | 8 | $i = (int) \grapheme_strlen($str); |
|
10234 | 8 | while ($i--) { |
|
10235 | 8 | $reversed_tmp = \grapheme_substr($str, $i, 1); |
|
10236 | 8 | if ($reversed_tmp !== false) { |
|
10237 | 8 | $reversed .= $reversed_tmp; |
|
10238 | } |
||
10239 | } |
||
10240 | } else { |
||
10241 | $i = (int) \mb_strlen($str); |
||
10242 | 8 | while ($i--) { |
|
10243 | $reversed_tmp = \mb_substr($str, $i, 1); |
||
10244 | if ($reversed_tmp !== false) { |
||
10245 | $reversed .= $reversed_tmp; |
||
10246 | } |
||
10247 | } |
||
10248 | } |
||
10249 | } else { |
||
10250 | $encoding = self::normalize_encoding($encoding, 'UTF-8'); |
||
10251 | |||
10252 | $i = (int) self::strlen($str, $encoding); |
||
10253 | while ($i--) { |
||
10254 | $reversed_tmp = self::substr($str, $i, 1, $encoding); |
||
10255 | if ($reversed_tmp !== false) { |
||
10256 | $reversed .= $reversed_tmp; |
||
10257 | } |
||
10258 | } |
||
10259 | } |
||
10260 | |||
10261 | 8 | return self::emoji_decode($reversed, true); |
|
10262 | } |
||
13694 |