Code Duplication    Length = 25-25 lines in 4 locations

src/Stringy.php 4 locations

@@ 2660-2684 (lines=25) @@
2657
   *
2658
   * @return static
2659
   */
2660
  public function beforeFirst(string $separator): self
2661
  {
2662
    if ($separator === '') {
2663
      return static::create();
2664
    }
2665
2666
    if ($this->str === '') {
2667
      return static::create();
2668
    }
2669
2670
    $offset = $this->indexOf($separator);
2671
    if ($offset === false) {
2672
      return static::create('', $this->encoding);
2673
    }
2674
2675
    return static::create(
2676
        UTF8::substr(
2677
            $this->str,
2678
            0,
2679
            $offset,
2680
            $this->encoding
2681
        ),
2682
        $this->encoding
2683
    );
2684
  }
2685
2686
  /**
2687
   * Gets the substring before the first occurrence of a separator.
@@ 2694-2718 (lines=25) @@
2691
   *
2692
   * @return static
2693
   */
2694
  public function beforeFirstIgnoreCase(string $separator): self
2695
  {
2696
    if ($separator === '') {
2697
      return static::create();
2698
    }
2699
2700
    if ($this->str === '') {
2701
      return static::create();
2702
    }
2703
2704
    $offset = $this->indexOfIgnoreCase($separator);
2705
    if ($offset === false) {
2706
      return static::create('', $this->encoding);
2707
    }
2708
2709
    return static::create(
2710
        UTF8::substr(
2711
            $this->str,
2712
            0,
2713
            $offset,
2714
            $this->encoding
2715
        ),
2716
        $this->encoding
2717
    );
2718
  }
2719
2720
  /**
2721
   * Gets the substring before the last occurrence of a separator.
@@ 2728-2752 (lines=25) @@
2725
   *
2726
   * @return static
2727
   */
2728
  public function beforeLast(string $separator): self
2729
  {
2730
    if ($separator === '') {
2731
      return static::create();
2732
    }
2733
2734
    if ($this->str === '') {
2735
      return static::create();
2736
    }
2737
2738
    $offset = $this->indexOfLast($separator);
2739
    if ($offset === false) {
2740
      return static::create('', $this->encoding);
2741
    }
2742
2743
    return static::create(
2744
        UTF8::substr(
2745
            $this->str,
2746
            0,
2747
            $offset,
2748
            $this->encoding
2749
        ),
2750
        $this->encoding
2751
    );
2752
  }
2753
2754
  /**
2755
   * Gets the substring before the last occurrence of a separator.
@@ 2762-2786 (lines=25) @@
2759
   *
2760
   * @return static
2761
   */
2762
  public function beforeLastIgnoreCase(string $separator): self
2763
  {
2764
    if ($separator === '') {
2765
      return static::create();
2766
    }
2767
2768
    if ($this->str === '') {
2769
      return static::create();
2770
    }
2771
2772
    $offset = $this->indexOfLastIgnoreCase($separator);
2773
    if ($offset === false) {
2774
      return static::create('', $this->encoding);
2775
    }
2776
2777
    return static::create(
2778
        UTF8::substr(
2779
            $this->str,
2780
            0,
2781
            $offset,
2782
            $this->encoding
2783
        ),
2784
        $this->encoding
2785
    );
2786
  }
2787
2788
  /**
2789
   * Returns the string with the first letter of each word capitalized,