Code Duplication    Length = 24-25 lines in 4 locations

src/Stringy.php 4 locations

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