Code Duplication    Length = 16-17 lines in 2 locations

src/Stringy.php 2 locations

@@ 739-755 (lines=17) @@
736
   *
737
   * @return Stringy Object with the resulting $str after the insertion
738
   */
739
  public function insert($substring, $index)
740
  {
741
    $stringy = static::create($this->str, $this->encoding);
742
    if ($index > $stringy->length()) {
743
      return $stringy;
744
    }
745
746
    $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
747
    $end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding);
748
749
    $stringy->str = $start . $substring . $end;
750
751
    return $stringy;
752
  }
753
754
  /**
755
   * Returns true if the string contains only alphabetic chars, false
756
   * otherwise.
757
   *
758
   * @return bool Whether or not $str contains only alphabetic chars
@@ 2037-2052 (lines=16) @@
2034
   *
2035
   * @return Stringy Object with the resulting $str after truncating
2036
   */
2037
  public function truncate($length, $substring = '')
2038
  {
2039
    $stringy = static::create($this->str, $this->encoding);
2040
    if ($length >= $stringy->length()) {
2041
      return $stringy;
2042
    }
2043
2044
    // Need to further trim the string so we can append the substring
2045
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
2046
    $length -= $substringLength;
2047
2048
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2049
    $stringy->str = $truncated . $substring;
2050
2051
    return $stringy;
2052
  }
2053
2054
  /**
2055
   * Returns a lowercase and trimmed string separated by underscores.