Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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