Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 2946-2993 (lines=48) @@
2943
   *                   <strong>2</strong> for UTF-16BE.
2944
   *                   </p>
2945
   */
2946
  public static function is_utf16($str)
2947
  {
2948
    $str = self::remove_bom($str);
2949
2950
    if (self::is_binary($str) === true) {
2951
2952
      $maybeUTF16LE = 0;
2953
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16LE');
2954
      if ($test) {
2955
        $test2 = \mb_convert_encoding($test, 'UTF-16LE', 'UTF-8');
2956
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16LE');
2957
        if ($test3 === $test) {
2958
          $strChars = self::count_chars($str, true);
2959
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2960
            if (in_array($test3char, $strChars, true) === true) {
2961
              $maybeUTF16LE++;
2962
            }
2963
          }
2964
        }
2965
      }
2966
2967
      $maybeUTF16BE = 0;
2968
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');
2969
      if ($test) {
2970
        $test2 = \mb_convert_encoding($test, 'UTF-16BE', 'UTF-8');
2971
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16BE');
2972
        if ($test3 === $test) {
2973
          $strChars = self::count_chars($str, true);
2974
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2975
            if (in_array($test3char, $strChars, true) === true) {
2976
              $maybeUTF16BE++;
2977
            }
2978
          }
2979
        }
2980
      }
2981
2982
      if ($maybeUTF16BE !== $maybeUTF16LE) {
2983
        if ($maybeUTF16LE > $maybeUTF16BE) {
2984
          return 1;
2985
        } else {
2986
          return 2;
2987
        }
2988
      }
2989
2990
    }
2991
2992
    return false;
2993
  }
2994
2995
  /**
2996
   * Check if the string is UTF-32.
@@ 3006-3053 (lines=48) @@
3003
   *                   <strong>2</strong> for UTF-32BE.
3004
   *                   </p>
3005
   */
3006
  public static function is_utf32($str)
3007
  {
3008
    $str = self::remove_bom($str);
3009
3010
    if (self::is_binary($str) === true) {
3011
3012
      $maybeUTF32LE = 0;
3013
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32LE');
3014
      if ($test) {
3015
        $test2 = \mb_convert_encoding($test, 'UTF-32LE', 'UTF-8');
3016
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32LE');
3017
        if ($test3 === $test) {
3018
          $strChars = self::count_chars($str, true);
3019
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3020
            if (in_array($test3char, $strChars, true) === true) {
3021
              $maybeUTF32LE++;
3022
            }
3023
          }
3024
        }
3025
      }
3026
3027
      $maybeUTF32BE = 0;
3028
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32BE');
3029
      if ($test) {
3030
        $test2 = \mb_convert_encoding($test, 'UTF-32BE', 'UTF-8');
3031
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32BE');
3032
        if ($test3 === $test) {
3033
          $strChars = self::count_chars($str, true);
3034
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3035
            if (in_array($test3char, $strChars, true) === true) {
3036
              $maybeUTF32BE++;
3037
            }
3038
          }
3039
        }
3040
      }
3041
3042
      if ($maybeUTF32BE !== $maybeUTF32LE) {
3043
        if ($maybeUTF32LE > $maybeUTF32BE) {
3044
          return 1;
3045
        } else {
3046
          return 2;
3047
        }
3048
      }
3049
3050
    }
3051
3052
    return false;
3053
  }
3054
3055
  /**
3056
   * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters.