Code Duplication    Length = 16-17 lines in 2 locations

src/Stringy.php 2 locations

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