Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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