Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 2908-2955 (lines=48) @@
2905
   *                   <strong>2</strong> for UTF-16BE.
2906
   *                   </p>
2907
   */
2908
  public static function is_utf16($str)
2909
  {
2910
    $str = self::remove_bom($str);
2911
2912
    if (self::is_binary($str) === true) {
2913
2914
      $maybeUTF16LE = 0;
2915
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16LE');
2916
      if ($test) {
2917
        $test2 = \mb_convert_encoding($test, 'UTF-16LE', 'UTF-8');
2918
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16LE');
2919
        if ($test3 === $test) {
2920
          $strChars = self::count_chars($str, true);
2921
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2922
            if (in_array($test3char, $strChars, true) === true) {
2923
              $maybeUTF16LE++;
2924
            }
2925
          }
2926
        }
2927
      }
2928
2929
      $maybeUTF16BE = 0;
2930
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');
2931
      if ($test) {
2932
        $test2 = \mb_convert_encoding($test, 'UTF-16BE', 'UTF-8');
2933
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16BE');
2934
        if ($test3 === $test) {
2935
          $strChars = self::count_chars($str, true);
2936
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2937
            if (in_array($test3char, $strChars, true) === true) {
2938
              $maybeUTF16BE++;
2939
            }
2940
          }
2941
        }
2942
      }
2943
2944
      if ($maybeUTF16BE !== $maybeUTF16LE) {
2945
        if ($maybeUTF16LE > $maybeUTF16BE) {
2946
          return 1;
2947
        } else {
2948
          return 2;
2949
        }
2950
      }
2951
2952
    }
2953
2954
    return false;
2955
  }
2956
2957
  /**
2958
   * Check if the string is UTF-32.
@@ 2968-3015 (lines=48) @@
2965
   *                   <strong>2</strong> for UTF-32BE.
2966
   *                   </p>
2967
   */
2968
  public static function is_utf32($str)
2969
  {
2970
    $str = self::remove_bom($str);
2971
2972
    if (self::is_binary($str) === true) {
2973
2974
      $maybeUTF32LE = 0;
2975
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32LE');
2976
      if ($test) {
2977
        $test2 = \mb_convert_encoding($test, 'UTF-32LE', 'UTF-8');
2978
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32LE');
2979
        if ($test3 === $test) {
2980
          $strChars = self::count_chars($str, true);
2981
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2982
            if (in_array($test3char, $strChars, true) === true) {
2983
              $maybeUTF32LE++;
2984
            }
2985
          }
2986
        }
2987
      }
2988
2989
      $maybeUTF32BE = 0;
2990
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32BE');
2991
      if ($test) {
2992
        $test2 = \mb_convert_encoding($test, 'UTF-32BE', 'UTF-8');
2993
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32BE');
2994
        if ($test3 === $test) {
2995
          $strChars = self::count_chars($str, true);
2996
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2997
            if (in_array($test3char, $strChars, true) === true) {
2998
              $maybeUTF32BE++;
2999
            }
3000
          }
3001
        }
3002
      }
3003
3004
      if ($maybeUTF32BE !== $maybeUTF32LE) {
3005
        if ($maybeUTF32LE > $maybeUTF32BE) {
3006
          return 1;
3007
        } else {
3008
          return 2;
3009
        }
3010
      }
3011
3012
    }
3013
3014
    return false;
3015
  }
3016
3017
  /**
3018
   * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters.