Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 2999-3046 (lines=48) @@
2996
   *                   <strong>2</strong> for UTF-16BE.
2997
   *                   </p>
2998
   */
2999
  public static function is_utf16($str)
3000
  {
3001
    $str = self::remove_bom($str);
3002
3003
    if (self::is_binary($str) === true) {
3004
3005
      $maybeUTF16LE = 0;
3006
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16LE');
3007
      if ($test) {
3008
        $test2 = \mb_convert_encoding($test, 'UTF-16LE', 'UTF-8');
3009
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16LE');
3010
        if ($test3 === $test) {
3011
          $strChars = self::count_chars($str, true);
3012
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3013
            if (in_array($test3char, $strChars, true) === true) {
3014
              $maybeUTF16LE++;
3015
            }
3016
          }
3017
        }
3018
      }
3019
3020
      $maybeUTF16BE = 0;
3021
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');
3022
      if ($test) {
3023
        $test2 = \mb_convert_encoding($test, 'UTF-16BE', 'UTF-8');
3024
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16BE');
3025
        if ($test3 === $test) {
3026
          $strChars = self::count_chars($str, true);
3027
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3028
            if (in_array($test3char, $strChars, true) === true) {
3029
              $maybeUTF16BE++;
3030
            }
3031
          }
3032
        }
3033
      }
3034
3035
      if ($maybeUTF16BE !== $maybeUTF16LE) {
3036
        if ($maybeUTF16LE > $maybeUTF16BE) {
3037
          return 1;
3038
        }
3039
3040
        return 2;
3041
      }
3042
3043
    }
3044
3045
    return false;
3046
  }
3047
3048
  /**
3049
   * Check if the string is UTF-32.
@@ 3059-3106 (lines=48) @@
3056
   *                   <strong>2</strong> for UTF-32BE.
3057
   *                   </p>
3058
   */
3059
  public static function is_utf32($str)
3060
  {
3061
    $str = self::remove_bom($str);
3062
3063
    if (self::is_binary($str) === true) {
3064
3065
      $maybeUTF32LE = 0;
3066
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32LE');
3067
      if ($test) {
3068
        $test2 = \mb_convert_encoding($test, 'UTF-32LE', 'UTF-8');
3069
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32LE');
3070
        if ($test3 === $test) {
3071
          $strChars = self::count_chars($str, true);
3072
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3073
            if (in_array($test3char, $strChars, true) === true) {
3074
              $maybeUTF32LE++;
3075
            }
3076
          }
3077
        }
3078
      }
3079
3080
      $maybeUTF32BE = 0;
3081
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32BE');
3082
      if ($test) {
3083
        $test2 = \mb_convert_encoding($test, 'UTF-32BE', 'UTF-8');
3084
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32BE');
3085
        if ($test3 === $test) {
3086
          $strChars = self::count_chars($str, true);
3087
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3088
            if (in_array($test3char, $strChars, true) === true) {
3089
              $maybeUTF32BE++;
3090
            }
3091
          }
3092
        }
3093
      }
3094
3095
      if ($maybeUTF32BE !== $maybeUTF32LE) {
3096
        if ($maybeUTF32LE > $maybeUTF32BE) {
3097
          return 1;
3098
        }
3099
3100
        return 2;
3101
      }
3102
3103
    }
3104
3105
    return false;
3106
  }
3107
3108
  /**
3109
   * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters.