Code Duplication    Length = 16-17 lines in 2 locations

src/Stringy.php 2 locations

@@ 737-753 (lines=17) @@
734
   *
735
   * @return Stringy Object with the resulting $str after the insertion
736
   */
737
  public function insert($substring, $index)
738
  {
739
    $stringy = static::create($this->str, $this->encoding);
740
    if ($index > $stringy->length()) {
741
      return $stringy;
742
    }
743
744
    $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
745
    $end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding);
746
747
    $stringy->str = $start . $substring . $end;
748
749
    return $stringy;
750
  }
751
752
  /**
753
   * Returns true if the string contains only alphabetic chars, false
754
   * otherwise.
755
   *
756
   * @return bool Whether or not $str contains only alphabetic chars
@@ 2020-2035 (lines=16) @@
2017
   *
2018
   * @return Stringy Object with the resulting $str after truncating
2019
   */
2020
  public function truncate($length, $substring = '')
2021
  {
2022
    $stringy = static::create($this->str, $this->encoding);
2023
    if ($length >= $stringy->length()) {
2024
      return $stringy;
2025
    }
2026
2027
    // Need to further trim the string so we can append the substring
2028
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
2029
    $length -= $substringLength;
2030
2031
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2032
    $stringy->str = $truncated . $substring;
2033
2034
    return $stringy;
2035
  }
2036
2037
  /**
2038
   * Returns a lowercase and trimmed string separated by underscores.