Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 3008-3055 (lines=48) @@
3005
   *                   <strong>2</strong> for UTF-16BE.
3006
   *                   </p>
3007
   */
3008
  public static function is_utf16($str)
3009
  {
3010
    $str = self::remove_bom($str);
3011
3012
    if (self::is_binary($str) === true) {
3013
3014
      $maybeUTF16LE = 0;
3015
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16LE');
3016
      if ($test) {
3017
        $test2 = \mb_convert_encoding($test, 'UTF-16LE', 'UTF-8');
3018
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16LE');
3019
        if ($test3 === $test) {
3020
          $strChars = self::count_chars($str, true);
3021
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3022
            if (in_array($test3char, $strChars, true) === true) {
3023
              $maybeUTF16LE++;
3024
            }
3025
          }
3026
        }
3027
      }
3028
3029
      $maybeUTF16BE = 0;
3030
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');
3031
      if ($test) {
3032
        $test2 = \mb_convert_encoding($test, 'UTF-16BE', 'UTF-8');
3033
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16BE');
3034
        if ($test3 === $test) {
3035
          $strChars = self::count_chars($str, true);
3036
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3037
            if (in_array($test3char, $strChars, true) === true) {
3038
              $maybeUTF16BE++;
3039
            }
3040
          }
3041
        }
3042
      }
3043
3044
      if ($maybeUTF16BE !== $maybeUTF16LE) {
3045
        if ($maybeUTF16LE > $maybeUTF16BE) {
3046
          return 1;
3047
        }
3048
3049
        return 2;
3050
      }
3051
3052
    }
3053
3054
    return false;
3055
  }
3056
3057
  /**
3058
   * Check if the string is UTF-32.
@@ 3068-3115 (lines=48) @@
3065
   *                   <strong>2</strong> for UTF-32BE.
3066
   *                   </p>
3067
   */
3068
  public static function is_utf32($str)
3069
  {
3070
    $str = self::remove_bom($str);
3071
3072
    if (self::is_binary($str) === true) {
3073
3074
      $maybeUTF32LE = 0;
3075
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32LE');
3076
      if ($test) {
3077
        $test2 = \mb_convert_encoding($test, 'UTF-32LE', 'UTF-8');
3078
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32LE');
3079
        if ($test3 === $test) {
3080
          $strChars = self::count_chars($str, true);
3081
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3082
            if (in_array($test3char, $strChars, true) === true) {
3083
              $maybeUTF32LE++;
3084
            }
3085
          }
3086
        }
3087
      }
3088
3089
      $maybeUTF32BE = 0;
3090
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32BE');
3091
      if ($test) {
3092
        $test2 = \mb_convert_encoding($test, 'UTF-32BE', 'UTF-8');
3093
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32BE');
3094
        if ($test3 === $test) {
3095
          $strChars = self::count_chars($str, true);
3096
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
3097
            if (in_array($test3char, $strChars, true) === true) {
3098
              $maybeUTF32BE++;
3099
            }
3100
          }
3101
        }
3102
      }
3103
3104
      if ($maybeUTF32BE !== $maybeUTF32LE) {
3105
        if ($maybeUTF32LE > $maybeUTF32BE) {
3106
          return 1;
3107
        }
3108
3109
        return 2;
3110
      }
3111
3112
    }
3113
3114
    return false;
3115
  }
3116
3117
  /**
3118
   * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters.