Code Duplication    Length = 24-25 lines in 4 locations

src/Stringy.php 4 locations

@@ 2673-2696 (lines=24) @@
2670
   *
2671
   * @return static
2672
   */
2673
  public function afterFirst(string $separator): self
2674
  {
2675
    if ($separator === '') {
2676
      return static::create();
2677
    }
2678
2679
    if ($this->str === '') {
2680
      return static::create();
2681
    }
2682
2683
    if (($offset = $this->indexOf($separator)) === false) {
2684
      return static::create();
2685
    }
2686
2687
    return static::create(
2688
        UTF8::substr(
2689
            $this->str,
2690
            $offset + UTF8::strlen($separator, $this->encoding),
2691
            null,
2692
            $this->encoding
2693
        ),
2694
        $this->encoding
2695
    );
2696
  }
2697
2698
  /**
2699
   * Gets the substring after the first occurrence of a separator.
@@ 2706-2729 (lines=24) @@
2703
   *
2704
   * @return static
2705
   */
2706
  public function afterFirstIgnoreCase(string $separator): self
2707
  {
2708
    if ($separator === '') {
2709
      return static::create();
2710
    }
2711
2712
    if ($this->str === '') {
2713
      return static::create();
2714
    }
2715
2716
    if (($offset = $this->indexOfIgnoreCase($separator)) === false) {
2717
      return static::create();
2718
    }
2719
2720
    return static::create(
2721
        UTF8::substr(
2722
            $this->str,
2723
            $offset + UTF8::strlen($separator, $this->encoding),
2724
            null,
2725
            $this->encoding
2726
        ),
2727
        $this->encoding
2728
    );
2729
  }
2730
2731
  /**
2732
   * Gets the substring after the last occurrence of a separator.
@@ 2739-2763 (lines=25) @@
2736
   *
2737
   * @return static
2738
   */
2739
  public function afterLastIgnoreCase(string $separator): self
2740
  {
2741
    if ($separator === '') {
2742
      return static::create();
2743
    }
2744
2745
    if ($this->str === '') {
2746
      return static::create();
2747
    }
2748
2749
    $offset = $this->indexOfLastIgnoreCase($separator);
2750
    if ($offset === false) {
2751
      return static::create('', $this->encoding);
2752
    }
2753
2754
    return static::create(
2755
        UTF8::substr(
2756
            $this->str,
2757
            $offset + UTF8::strlen($separator, $this->encoding),
2758
            null,
2759
            $this->encoding
2760
        ),
2761
        $this->encoding
2762
    );
2763
  }
2764
2765
  /**
2766
   * Gets the substring after the last occurrence of a separator.
@@ 2773-2797 (lines=25) @@
2770
   *
2771
   * @return static
2772
   */
2773
  public function afterLast(string $separator): self
2774
  {
2775
    if ($separator === '') {
2776
      return static::create();
2777
    }
2778
2779
    if ($this->str === '') {
2780
      return static::create();
2781
    }
2782
2783
    $offset = $this->indexOfLast($separator);
2784
    if ($offset === false) {
2785
      return static::create('', $this->encoding);
2786
    }
2787
2788
    return static::create(
2789
        UTF8::substr(
2790
            $this->str,
2791
            $offset + UTF8::strlen($separator, $this->encoding),
2792
            null,
2793
            $this->encoding
2794
        ),
2795
        $this->encoding
2796
    );
2797
  }
2798
2799
  /**
2800
   * Gets the substring before the first occurrence of a separator.