Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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