Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 2770-2817 (lines=48) @@
2767
   *                   <strong>2</strong> for UTF-16BE.
2768
   *                   </p>
2769
   */
2770
  public static function is_utf16($str)
2771
  {
2772
    $str = self::remove_bom($str);
2773
2774
    if (self::is_binary($str)) {
2775
2776
      $maybeUTF16LE = 0;
2777
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16LE');
2778
      if ($test) {
2779
        $test2 = \mb_convert_encoding($test, 'UTF-16LE', 'UTF-8');
2780
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16LE');
2781
        if ($test3 === $test) {
2782
          $strChars = self::count_chars($str, true);
2783
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2784
            if (in_array($test3char, $strChars, true) === true) {
2785
              $maybeUTF16LE++;
2786
            }
2787
          }
2788
        }
2789
      }
2790
2791
      $maybeUTF16BE = 0;
2792
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');
2793
      if ($test) {
2794
        $test2 = \mb_convert_encoding($test, 'UTF-16BE', 'UTF-8');
2795
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16BE');
2796
        if ($test3 === $test) {
2797
          $strChars = self::count_chars($str, true);
2798
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2799
            if (in_array($test3char, $strChars, true) === true) {
2800
              $maybeUTF16BE++;
2801
            }
2802
          }
2803
        }
2804
      }
2805
2806
      if ($maybeUTF16BE !== $maybeUTF16LE) {
2807
        if ($maybeUTF16LE > $maybeUTF16BE) {
2808
          return 1;
2809
        } else {
2810
          return 2;
2811
        }
2812
      }
2813
2814
    }
2815
2816
    return false;
2817
  }
2818
2819
  /**
2820
   * Check if the string is UTF-32.
@@ 2830-2877 (lines=48) @@
2827
   *                   <strong>2</strong> for UTF-32BE.
2828
   *                   </p>
2829
   */
2830
  public static function is_utf32($str)
2831
  {
2832
    $str = self::remove_bom($str);
2833
2834
    if (self::is_binary($str)) {
2835
2836
      $maybeUTF32LE = 0;
2837
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32LE');
2838
      if ($test) {
2839
        $test2 = \mb_convert_encoding($test, 'UTF-32LE', 'UTF-8');
2840
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32LE');
2841
        if ($test3 === $test) {
2842
          $strChars = self::count_chars($str, true);
2843
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2844
            if (in_array($test3char, $strChars, true) === true) {
2845
              $maybeUTF32LE++;
2846
            }
2847
          }
2848
        }
2849
      }
2850
2851
      $maybeUTF32BE = 0;
2852
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32BE');
2853
      if ($test) {
2854
        $test2 = \mb_convert_encoding($test, 'UTF-32BE', 'UTF-8');
2855
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32BE');
2856
        if ($test3 === $test) {
2857
          $strChars = self::count_chars($str, true);
2858
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2859
            if (in_array($test3char, $strChars, true) === true) {
2860
              $maybeUTF32BE++;
2861
            }
2862
          }
2863
        }
2864
      }
2865
2866
      if ($maybeUTF32BE !== $maybeUTF32LE) {
2867
        if ($maybeUTF32LE > $maybeUTF32BE) {
2868
          return 1;
2869
        } else {
2870
          return 2;
2871
        }
2872
      }
2873
2874
    }
2875
2876
    return false;
2877
  }
2878
2879
  /**
2880
   * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters.