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
@@ 1972-1987 (lines=16) @@
1969
   *
1970
   * @return Stringy Object with the resulting $str after truncating
1971
   */
1972
  public function truncate($length, $substring = '')
1973
  {
1974
    $stringy = static::create($this->str, $this->encoding);
1975
    if ($length >= $stringy->length()) {
1976
      return $stringy;
1977
    }
1978
1979
    // Need to further trim the string so we can append the substring
1980
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
1981
    $length -= $substringLength;
1982
1983
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
1984
    $stringy->str = $truncated . $substring;
1985
1986
    return $stringy;
1987
  }
1988
1989
  /**
1990
   * Returns a lowercase and trimmed string separated by underscores.