Code Duplication    Length = 12-12 lines in 2 locations

src/Stringy.php 2 locations

@@ 626-637 (lines=12) @@
623
   *
624
   * @return static <p>Object with its $str being the first $n chars.</p>
625
   */
626
  public function first(int $n): self
627
  {
628
    $stringy = static::create($this->str, $this->encoding);
629
630
    if ($n < 0) {
631
      $stringy->str = '';
632
    } else {
633
      return $stringy->substr(0, $n);
634
    }
635
636
    return $stringy;
637
  }
638
639
  /**
640
   * Returns the encoding used by the Stringy object.
@@ 1106-1117 (lines=12) @@
1103
   *
1104
   * @return static <p>Object with its $str being the last $n chars.</p>
1105
   */
1106
  public function last(int $n): self
1107
  {
1108
    $stringy = static::create($this->str, $this->encoding);
1109
1110
    if ($n <= 0) {
1111
      $stringy->str = '';
1112
    } else {
1113
      return $stringy->substr(-$n);
1114
    }
1115
1116
    return $stringy;
1117
  }
1118
1119
  /**
1120
   * Splits on newlines and carriage returns, returning an array of Stringy