Code Duplication    Length = 16-17 lines in 2 locations

src/Stringy.php 2 locations

@@ 679-695 (lines=17) @@
676
   *
677
   * @return Stringy Object with the resulting $str after the insertion
678
   */
679
  public function insert($substring, $index)
680
  {
681
    $stringy = static::create($this->str, $this->encoding);
682
    if ($index > $stringy->length()) {
683
      return $stringy;
684
    }
685
686
    $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
687
    $end = UTF8::substr(
688
        $stringy->str, $index, $stringy->length(),
689
        $stringy->encoding
690
    );
691
692
    $stringy->str = $start . $substring . $end;
693
694
    return $stringy;
695
  }
696
697
  /**
698
   * Returns true if the string contains only alphabetic chars, false
@@ 1746-1761 (lines=16) @@
1743
   *
1744
   * @return Stringy Object with the resulting $str after truncating
1745
   */
1746
  public function truncate($length, $substring = '')
1747
  {
1748
    $stringy = static::create($this->str, $this->encoding);
1749
    if ($length >= $stringy->length()) {
1750
      return $stringy;
1751
    }
1752
1753
    // Need to further trim the string so we can append the substring
1754
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
1755
    $length -= $substringLength;
1756
1757
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
1758
    $stringy->str = $truncated . $substring;
1759
1760
    return $stringy;
1761
  }
1762
1763
  /**
1764
   * Returns a lowercase and trimmed string separated by underscores.