Code Duplication    Length = 24-25 lines in 8 locations

src/Stringy.php 8 locations

@@ 2532-2555 (lines=24) @@
2529
   *
2530
   * @return static
2531
   */
2532
  public function afterFirst($separator)
2533
  {
2534
    if ($separator === '') {
2535
      return static::create('');
2536
    }
2537
2538
    if ($this->str === '') {
2539
      return static::create('');
2540
    }
2541
2542
    if (($offset = $this->indexOf($separator)) === false) {
2543
      return static::create('');
2544
    }
2545
2546
    return static::create(
2547
        UTF8::substr(
2548
            $this->str,
2549
            $offset + UTF8::strlen($separator, $this->encoding),
2550
            null,
2551
            $this->encoding
2552
        ),
2553
        $this->encoding
2554
    );
2555
  }
2556
2557
  /**
2558
   * Gets the substring after the first occurrence of a separator.
@@ 2565-2588 (lines=24) @@
2562
   *
2563
   * @return static
2564
   */
2565
  public function afterFirstIgnoreCase($separator)
2566
  {
2567
    if ($separator === '') {
2568
      return static::create('');
2569
    }
2570
2571
    if ($this->str === '') {
2572
      return static::create('');
2573
    }
2574
2575
    if (($offset = $this->indexOfIgnoreCase($separator)) === false) {
2576
      return static::create('');
2577
    }
2578
2579
    return static::create(
2580
        UTF8::substr(
2581
            $this->str,
2582
            $offset + UTF8::strlen($separator, $this->encoding),
2583
            null,
2584
            $this->encoding
2585
        ),
2586
        $this->encoding
2587
    );
2588
  }
2589
2590
  /**
2591
   * Gets the substring after the last occurrence of a separator.
@@ 2598-2622 (lines=25) @@
2595
   *
2596
   * @return static
2597
   */
2598
  public function afterLastIgnoreCase($separator)
2599
  {
2600
    if ($separator === '') {
2601
      return static::create('');
2602
    }
2603
2604
    if ($this->str === '') {
2605
      return static::create('');
2606
    }
2607
2608
    $offset = $this->indexOfLastIgnoreCase($separator);
2609
    if ($offset === false) {
2610
      return static::create('', $this->encoding);
2611
    }
2612
2613
    return static::create(
2614
        UTF8::substr(
2615
            $this->str,
2616
            $offset + UTF8::strlen($separator, $this->encoding),
2617
            null,
2618
            $this->encoding
2619
        ),
2620
        $this->encoding
2621
    );
2622
  }
2623
2624
  /**
2625
   * Gets the substring after the last occurrence of a separator.
@@ 2632-2656 (lines=25) @@
2629
   *
2630
   * @return static
2631
   */
2632
  public function afterLast($separator)
2633
  {
2634
    if ($separator === '') {
2635
      return static::create('');
2636
    }
2637
2638
    if ($this->str === '') {
2639
      return static::create('');
2640
    }
2641
2642
    $offset = $this->indexOfLast($separator);
2643
    if ($offset === false) {
2644
      return static::create('', $this->encoding);
2645
    }
2646
2647
    return static::create(
2648
        UTF8::substr(
2649
            $this->str,
2650
            $offset + UTF8::strlen($separator, $this->encoding),
2651
            null,
2652
            $this->encoding
2653
        ),
2654
        $this->encoding
2655
    );
2656
  }
2657
2658
  /**
2659
   * Gets the substring before the first occurrence of a separator.
@@ 2666-2690 (lines=25) @@
2663
   *
2664
   * @return static
2665
   */
2666
  public function beforeFirst($separator)
2667
  {
2668
    if ($separator === '') {
2669
      return static::create('');
2670
    }
2671
2672
    if ($this->str === '') {
2673
      return static::create('');
2674
    }
2675
2676
    $offset = $this->indexOf($separator);
2677
    if ($offset === false) {
2678
      return static::create('', $this->encoding);
2679
    }
2680
2681
    return static::create(
2682
        UTF8::substr(
2683
            $this->str,
2684
            0,
2685
            $offset,
2686
            $this->encoding
2687
        ),
2688
        $this->encoding
2689
    );
2690
  }
2691
2692
  /**
2693
   * Gets the substring before the first occurrence of a separator.
@@ 2700-2724 (lines=25) @@
2697
   *
2698
   * @return static
2699
   */
2700
  public function beforeFirstIgnoreCase($separator)
2701
  {
2702
    if ($separator === '') {
2703
      return static::create('');
2704
    }
2705
2706
    if ($this->str === '') {
2707
      return static::create('');
2708
    }
2709
2710
    $offset = $this->indexOfIgnoreCase($separator);
2711
    if ($offset === false) {
2712
      return static::create('', $this->encoding);
2713
    }
2714
2715
    return static::create(
2716
        UTF8::substr(
2717
            $this->str,
2718
            0,
2719
            $offset,
2720
            $this->encoding
2721
        ),
2722
        $this->encoding
2723
    );
2724
  }
2725
2726
  /**
2727
   * Gets the substring before the last occurrence of a separator.
@@ 2734-2758 (lines=25) @@
2731
   *
2732
   * @return static
2733
   */
2734
  public function beforeLast($separator)
2735
  {
2736
    if ($separator === '') {
2737
      return static::create('');
2738
    }
2739
2740
    if ($this->str === '') {
2741
      return static::create('');
2742
    }
2743
2744
    $offset = $this->indexOfLast($separator);
2745
    if ($offset === false) {
2746
      return static::create('', $this->encoding);
2747
    }
2748
2749
    return static::create(
2750
        UTF8::substr(
2751
            $this->str,
2752
            0,
2753
            $offset,
2754
            $this->encoding
2755
        ),
2756
        $this->encoding
2757
    );
2758
  }
2759
2760
  /**
2761
   * Gets the substring before the last occurrence of a separator.
@@ 2768-2792 (lines=25) @@
2765
   *
2766
   * @return static
2767
   */
2768
  public function beforeLastIgnoreCase($separator)
2769
  {
2770
    if ($separator === '') {
2771
      return static::create('');
2772
    }
2773
2774
    if ($this->str === '') {
2775
      return static::create('');
2776
    }
2777
2778
    $offset = $this->indexOfLastIgnoreCase($separator);
2779
    if ($offset === false) {
2780
      return static::create('', $this->encoding);
2781
    }
2782
2783
    return static::create(
2784
        UTF8::substr(
2785
            $this->str,
2786
            0,
2787
            $offset,
2788
            $this->encoding
2789
        ),
2790
        $this->encoding
2791
    );
2792
  }
2793
2794
  /**
2795
   * Returns the string with the first letter of each word capitalized,