Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 2892-2939 (lines=48) @@
2889
   *                   <strong>2</strong> for UTF-16BE.
2890
   *                   </p>
2891
   */
2892
  public static function is_utf16($str)
2893
  {
2894
    $str = self::remove_bom($str);
2895
2896
    if (self::is_binary($str) === true) {
2897
2898
      $maybeUTF16LE = 0;
2899
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16LE');
2900
      if ($test) {
2901
        $test2 = \mb_convert_encoding($test, 'UTF-16LE', 'UTF-8');
2902
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16LE');
2903
        if ($test3 === $test) {
2904
          $strChars = self::count_chars($str, true);
2905
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2906
            if (in_array($test3char, $strChars, true) === true) {
2907
              $maybeUTF16LE++;
2908
            }
2909
          }
2910
        }
2911
      }
2912
2913
      $maybeUTF16BE = 0;
2914
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');
2915
      if ($test) {
2916
        $test2 = \mb_convert_encoding($test, 'UTF-16BE', 'UTF-8');
2917
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16BE');
2918
        if ($test3 === $test) {
2919
          $strChars = self::count_chars($str, true);
2920
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2921
            if (in_array($test3char, $strChars, true) === true) {
2922
              $maybeUTF16BE++;
2923
            }
2924
          }
2925
        }
2926
      }
2927
2928
      if ($maybeUTF16BE !== $maybeUTF16LE) {
2929
        if ($maybeUTF16LE > $maybeUTF16BE) {
2930
          return 1;
2931
        } else {
2932
          return 2;
2933
        }
2934
      }
2935
2936
    }
2937
2938
    return false;
2939
  }
2940
2941
  /**
2942
   * Check if the string is UTF-32.
@@ 2952-2999 (lines=48) @@
2949
   *                   <strong>2</strong> for UTF-32BE.
2950
   *                   </p>
2951
   */
2952
  public static function is_utf32($str)
2953
  {
2954
    $str = self::remove_bom($str);
2955
2956
    if (self::is_binary($str) === true) {
2957
2958
      $maybeUTF32LE = 0;
2959
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32LE');
2960
      if ($test) {
2961
        $test2 = \mb_convert_encoding($test, 'UTF-32LE', 'UTF-8');
2962
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32LE');
2963
        if ($test3 === $test) {
2964
          $strChars = self::count_chars($str, true);
2965
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2966
            if (in_array($test3char, $strChars, true) === true) {
2967
              $maybeUTF32LE++;
2968
            }
2969
          }
2970
        }
2971
      }
2972
2973
      $maybeUTF32BE = 0;
2974
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32BE');
2975
      if ($test) {
2976
        $test2 = \mb_convert_encoding($test, 'UTF-32BE', 'UTF-8');
2977
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32BE');
2978
        if ($test3 === $test) {
2979
          $strChars = self::count_chars($str, true);
2980
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2981
            if (in_array($test3char, $strChars, true) === true) {
2982
              $maybeUTF32BE++;
2983
            }
2984
          }
2985
        }
2986
      }
2987
2988
      if ($maybeUTF32BE !== $maybeUTF32LE) {
2989
        if ($maybeUTF32LE > $maybeUTF32BE) {
2990
          return 1;
2991
        } else {
2992
          return 2;
2993
        }
2994
      }
2995
2996
    }
2997
2998
    return false;
2999
  }
3000
3001
  /**
3002
   * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters.