Code Duplication    Length = 12-12 lines in 2 locations

src/Stringy.php 2 locations

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