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
@@ 2041-2056 (lines=16) @@
2038
   *
2039
   * @return Stringy Object with the resulting $str after truncating
2040
   */
2041
  public function truncate($length, $substring = '')
2042
  {
2043
    $stringy = static::create($this->str, $this->encoding);
2044
    if ($length >= $stringy->length()) {
2045
      return $stringy;
2046
    }
2047
2048
    // Need to further trim the string so we can append the substring
2049
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
2050
    $length -= $substringLength;
2051
2052
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2053
    $stringy->str = $truncated . $substring;
2054
2055
    return $stringy;
2056
  }
2057
2058
  /**
2059
   * Returns a lowercase and trimmed string separated by underscores.