Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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