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
@@ 1747-1762 (lines=16) @@
1744
   *
1745
   * @return Stringy Object with the resulting $str after truncating
1746
   */
1747
  public function truncate($length, $substring = '')
1748
  {
1749
    $stringy = static::create($this->str, $this->encoding);
1750
    if ($length >= $stringy->length()) {
1751
      return $stringy;
1752
    }
1753
1754
    // Need to further trim the string so we can append the substring
1755
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
1756
    $length -= $substringLength;
1757
1758
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
1759
    $stringy->str = $truncated . $substring;
1760
1761
    return $stringy;
1762
  }
1763
1764
  /**
1765
   * Returns a lowercase and trimmed string separated by underscores.