Code Duplication    Length = 48-48 lines in 2 locations

src/voku/helper/UTF8.php 2 locations

@@ 2565-2612 (lines=48) @@
2562
   *                   <strong>2</strong> for UTF-16BE.
2563
   *                   </p>
2564
   */
2565
  public static function is_utf16($str)
2566
  {
2567
    $str = self::remove_bom($str);
2568
2569
    if (self::is_binary($str)) {
2570
2571
      $maybeUTF16LE = 0;
2572
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16LE');
2573
      if ($test) {
2574
        $test2 = \mb_convert_encoding($test, 'UTF-16LE', 'UTF-8');
2575
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16LE');
2576
        if ($test3 === $test) {
2577
          $strChars = self::count_chars($str, true);
2578
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2579
            if (in_array($test3char, $strChars, true) === true) {
2580
              $maybeUTF16LE++;
2581
            }
2582
          }
2583
        }
2584
      }
2585
2586
      $maybeUTF16BE = 0;
2587
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-16BE');
2588
      if ($test) {
2589
        $test2 = \mb_convert_encoding($test, 'UTF-16BE', 'UTF-8');
2590
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-16BE');
2591
        if ($test3 === $test) {
2592
          $strChars = self::count_chars($str, true);
2593
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2594
            if (in_array($test3char, $strChars, true) === true) {
2595
              $maybeUTF16BE++;
2596
            }
2597
          }
2598
        }
2599
      }
2600
2601
      if ($maybeUTF16BE !== $maybeUTF16LE) {
2602
        if ($maybeUTF16LE > $maybeUTF16BE) {
2603
          return 1;
2604
        } else {
2605
          return 2;
2606
        }
2607
      }
2608
2609
    }
2610
2611
    return false;
2612
  }
2613
2614
  /**
2615
   * Check if the string is UTF-32.
@@ 2625-2672 (lines=48) @@
2622
   *                   <strong>2</strong> for UTF-32BE.
2623
   *                   </p>
2624
   */
2625
  public static function is_utf32($str)
2626
  {
2627
    $str = self::remove_bom($str);
2628
2629
    if (self::is_binary($str)) {
2630
2631
      $maybeUTF32LE = 0;
2632
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32LE');
2633
      if ($test) {
2634
        $test2 = \mb_convert_encoding($test, 'UTF-32LE', 'UTF-8');
2635
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32LE');
2636
        if ($test3 === $test) {
2637
          $strChars = self::count_chars($str, true);
2638
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2639
            if (in_array($test3char, $strChars, true) === true) {
2640
              $maybeUTF32LE++;
2641
            }
2642
          }
2643
        }
2644
      }
2645
2646
      $maybeUTF32BE = 0;
2647
      $test = \mb_convert_encoding($str, 'UTF-8', 'UTF-32BE');
2648
      if ($test) {
2649
        $test2 = \mb_convert_encoding($test, 'UTF-32BE', 'UTF-8');
2650
        $test3 = \mb_convert_encoding($test2, 'UTF-8', 'UTF-32BE');
2651
        if ($test3 === $test) {
2652
          $strChars = self::count_chars($str, true);
2653
          foreach (self::count_chars($test3, true) as $test3char => $test3charEmpty) {
2654
            if (in_array($test3char, $strChars, true) === true) {
2655
              $maybeUTF32BE++;
2656
            }
2657
          }
2658
        }
2659
      }
2660
2661
      if ($maybeUTF32BE !== $maybeUTF32LE) {
2662
        if ($maybeUTF32LE > $maybeUTF32BE) {
2663
          return 1;
2664
        } else {
2665
          return 2;
2666
        }
2667
      }
2668
2669
    }
2670
2671
    return false;
2672
  }
2673
2674
  /**
2675
   * Checks whether the passed string contains only byte sequences that appear valid UTF-8 characters.