Code Duplication    Length = 24-25 lines in 4 locations

src/Stringy.php 4 locations

@@ 2526-2549 (lines=24) @@
2523
   *
2524
   * @return static
2525
   */
2526
  public function afterFirst(string $separator): self
2527
  {
2528
    if ($separator === '') {
2529
      return static::create();
2530
    }
2531
2532
    if ($this->str === '') {
2533
      return static::create();
2534
    }
2535
2536
    if (($offset = $this->indexOf($separator)) === false) {
2537
      return static::create();
2538
    }
2539
2540
    return static::create(
2541
        UTF8::substr(
2542
            $this->str,
2543
            $offset + UTF8::strlen($separator, $this->encoding),
2544
            null,
2545
            $this->encoding
2546
        ),
2547
        $this->encoding
2548
    );
2549
  }
2550
2551
  /**
2552
   * Gets the substring after the first occurrence of a separator.
@@ 2559-2582 (lines=24) @@
2556
   *
2557
   * @return static
2558
   */
2559
  public function afterFirstIgnoreCase(string $separator): self
2560
  {
2561
    if ($separator === '') {
2562
      return static::create();
2563
    }
2564
2565
    if ($this->str === '') {
2566
      return static::create();
2567
    }
2568
2569
    if (($offset = $this->indexOfIgnoreCase($separator)) === false) {
2570
      return static::create();
2571
    }
2572
2573
    return static::create(
2574
        UTF8::substr(
2575
            $this->str,
2576
            $offset + UTF8::strlen($separator, $this->encoding),
2577
            null,
2578
            $this->encoding
2579
        ),
2580
        $this->encoding
2581
    );
2582
  }
2583
2584
  /**
2585
   * Gets the substring after the last occurrence of a separator.
@@ 2592-2616 (lines=25) @@
2589
   *
2590
   * @return static
2591
   */
2592
  public function afterLastIgnoreCase(string $separator): self
2593
  {
2594
    if ($separator === '') {
2595
      return static::create();
2596
    }
2597
2598
    if ($this->str === '') {
2599
      return static::create();
2600
    }
2601
2602
    $offset = $this->indexOfLastIgnoreCase($separator);
2603
    if ($offset === false) {
2604
      return static::create('', $this->encoding);
2605
    }
2606
2607
    return static::create(
2608
        UTF8::substr(
2609
            $this->str,
2610
            $offset + UTF8::strlen($separator, $this->encoding),
2611
            null,
2612
            $this->encoding
2613
        ),
2614
        $this->encoding
2615
    );
2616
  }
2617
2618
  /**
2619
   * Gets the substring after the last occurrence of a separator.
@@ 2626-2650 (lines=25) @@
2623
   *
2624
   * @return static
2625
   */
2626
  public function afterLast(string $separator): self
2627
  {
2628
    if ($separator === '') {
2629
      return static::create();
2630
    }
2631
2632
    if ($this->str === '') {
2633
      return static::create();
2634
    }
2635
2636
    $offset = $this->indexOfLast($separator);
2637
    if ($offset === false) {
2638
      return static::create('', $this->encoding);
2639
    }
2640
2641
    return static::create(
2642
        UTF8::substr(
2643
            $this->str,
2644
            $offset + UTF8::strlen($separator, $this->encoding),
2645
            null,
2646
            $this->encoding
2647
        ),
2648
        $this->encoding
2649
    );
2650
  }
2651
2652
  /**
2653
   * Gets the substring before the first occurrence of a separator.