Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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