Code Duplication    Length = 25-25 lines in 4 locations

src/Stringy.php 4 locations

@@ 2804-2828 (lines=25) @@
2801
   *
2802
   * @return static
2803
   */
2804
  public function beforeFirst(string $separator): self
2805
  {
2806
    if ($separator === '') {
2807
      return static::create();
2808
    }
2809
2810
    if ($this->str === '') {
2811
      return static::create();
2812
    }
2813
2814
    $offset = $this->indexOf($separator);
2815
    if ($offset === false) {
2816
      return static::create('', $this->encoding);
2817
    }
2818
2819
    return static::create(
2820
        UTF8::substr(
2821
            $this->str,
2822
            0,
2823
            $offset,
2824
            $this->encoding
2825
        ),
2826
        $this->encoding
2827
    );
2828
  }
2829
2830
  /**
2831
   * Gets the substring before the first occurrence of a separator.
@@ 2838-2862 (lines=25) @@
2835
   *
2836
   * @return static
2837
   */
2838
  public function beforeFirstIgnoreCase(string $separator): self
2839
  {
2840
    if ($separator === '') {
2841
      return static::create();
2842
    }
2843
2844
    if ($this->str === '') {
2845
      return static::create();
2846
    }
2847
2848
    $offset = $this->indexOfIgnoreCase($separator);
2849
    if ($offset === false) {
2850
      return static::create('', $this->encoding);
2851
    }
2852
2853
    return static::create(
2854
        UTF8::substr(
2855
            $this->str,
2856
            0,
2857
            $offset,
2858
            $this->encoding
2859
        ),
2860
        $this->encoding
2861
    );
2862
  }
2863
2864
  /**
2865
   * Gets the substring before the last occurrence of a separator.
@@ 2872-2896 (lines=25) @@
2869
   *
2870
   * @return static
2871
   */
2872
  public function beforeLast(string $separator): self
2873
  {
2874
    if ($separator === '') {
2875
      return static::create();
2876
    }
2877
2878
    if ($this->str === '') {
2879
      return static::create();
2880
    }
2881
2882
    $offset = $this->indexOfLast($separator);
2883
    if ($offset === false) {
2884
      return static::create('', $this->encoding);
2885
    }
2886
2887
    return static::create(
2888
        UTF8::substr(
2889
            $this->str,
2890
            0,
2891
            $offset,
2892
            $this->encoding
2893
        ),
2894
        $this->encoding
2895
    );
2896
  }
2897
2898
  /**
2899
   * Gets the substring before the last occurrence of a separator.
@@ 2906-2930 (lines=25) @@
2903
   *
2904
   * @return static
2905
   */
2906
  public function beforeLastIgnoreCase(string $separator): self
2907
  {
2908
    if ($separator === '') {
2909
      return static::create();
2910
    }
2911
2912
    if ($this->str === '') {
2913
      return static::create();
2914
    }
2915
2916
    $offset = $this->indexOfLastIgnoreCase($separator);
2917
    if ($offset === false) {
2918
      return static::create('', $this->encoding);
2919
    }
2920
2921
    return static::create(
2922
        UTF8::substr(
2923
            $this->str,
2924
            0,
2925
            $offset,
2926
            $this->encoding
2927
        ),
2928
        $this->encoding
2929
    );
2930
  }
2931
2932
  /**
2933
   * Returns the string with the first letter of each word capitalized,