Code Duplication    Length = 16-17 lines in 2 locations

src/Stringy.php 2 locations

@@ 741-757 (lines=17) @@
738
   *
739
   * @return Stringy Object with the resulting $str after the insertion
740
   */
741
  public function insert($substring, $index)
742
  {
743
    $stringy = static::create($this->str, $this->encoding);
744
    if ($index > $stringy->length()) {
745
      return $stringy;
746
    }
747
748
    $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
749
    $end = UTF8::substr(
750
        $stringy->str, $index, $stringy->length(),
751
        $stringy->encoding
752
    );
753
754
    $stringy->str = $start . $substring . $end;
755
756
    return $stringy;
757
  }
758
759
  /**
760
   * Returns true if the string contains only alphabetic chars, false
@@ 1976-1991 (lines=16) @@
1973
   *
1974
   * @return Stringy Object with the resulting $str after truncating
1975
   */
1976
  public function truncate($length, $substring = '')
1977
  {
1978
    $stringy = static::create($this->str, $this->encoding);
1979
    if ($length >= $stringy->length()) {
1980
      return $stringy;
1981
    }
1982
1983
    // Need to further trim the string so we can append the substring
1984
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
1985
    $length -= $substringLength;
1986
1987
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
1988
    $stringy->str = $truncated . $substring;
1989
1990
    return $stringy;
1991
  }
1992
1993
  /**
1994
   * Returns a lowercase and trimmed string separated by underscores.