Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 2794-2841 (lines=48) @@
2791
   *                   <strong>2</strong> for UTF-16BE.
2792
   *                   </p>
2793
   */
2794
  public static function is_utf16($str)
2795
  {
2796
    $str = self::remove_bom($str);
2797
2798
    if (self::is_binary($str)) {
2799
2800
      $maybeUTF16LE = 0;
2801
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16LE');
2802
      if ($test) {
2803
        $test2 = \mb_convert_encoding($test, 'UTF-16LE', 'UTF-8');
2804
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16LE');
2805
        if ($test3 === $test) {
2806
          $strChars = self::count_chars($str, true);
2807
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2808
            if (in_array($test3char, $strChars, true) === true) {
2809
              $maybeUTF16LE++;
2810
            }
2811
          }
2812
        }
2813
      }
2814
2815
      $maybeUTF16BE = 0;
2816
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');
2817
      if ($test) {
2818
        $test2 = \mb_convert_encoding($test, 'UTF-16BE', 'UTF-8');
2819
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16BE');
2820
        if ($test3 === $test) {
2821
          $strChars = self::count_chars($str, true);
2822
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2823
            if (in_array($test3char, $strChars, true) === true) {
2824
              $maybeUTF16BE++;
2825
            }
2826
          }
2827
        }
2828
      }
2829
2830
      if ($maybeUTF16BE !== $maybeUTF16LE) {
2831
        if ($maybeUTF16LE > $maybeUTF16BE) {
2832
          return 1;
2833
        } else {
2834
          return 2;
2835
        }
2836
      }
2837
2838
    }
2839
2840
    return false;
2841
  }
2842
2843
  /**
2844
   * Check if the string is UTF-32.
@@ 2854-2901 (lines=48) @@
2851
   *                   <strong>2</strong> for UTF-32BE.
2852
   *                   </p>
2853
   */
2854
  public static function is_utf32($str)
2855
  {
2856
    $str = self::remove_bom($str);
2857
2858
    if (self::is_binary($str)) {
2859
2860
      $maybeUTF32LE = 0;
2861
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32LE');
2862
      if ($test) {
2863
        $test2 = \mb_convert_encoding($test, 'UTF-32LE', 'UTF-8');
2864
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32LE');
2865
        if ($test3 === $test) {
2866
          $strChars = self::count_chars($str, true);
2867
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2868
            if (in_array($test3char, $strChars, true) === true) {
2869
              $maybeUTF32LE++;
2870
            }
2871
          }
2872
        }
2873
      }
2874
2875
      $maybeUTF32BE = 0;
2876
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32BE');
2877
      if ($test) {
2878
        $test2 = \mb_convert_encoding($test, 'UTF-32BE', 'UTF-8');
2879
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32BE');
2880
        if ($test3 === $test) {
2881
          $strChars = self::count_chars($str, true);
2882
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2883
            if (in_array($test3char, $strChars, true) === true) {
2884
              $maybeUTF32BE++;
2885
            }
2886
          }
2887
        }
2888
      }
2889
2890
      if ($maybeUTF32BE !== $maybeUTF32LE) {
2891
        if ($maybeUTF32LE > $maybeUTF32BE) {
2892
          return 1;
2893
        } else {
2894
          return 2;
2895
        }
2896
      }
2897
2898
    }
2899
2900
    return false;
2901
  }
2902
2903
  /**
2904
   * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters.