Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

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