Code Duplication    Length = 16-17 lines in 2 locations

src/Stringy.php 2 locations

@@ 764-780 (lines=17) @@
761
   *
762
   * @return Stringy Object with the resulting $str after the insertion
763
   */
764
  public function insert($substring, $index)
765
  {
766
    $stringy = static::create($this->str, $this->encoding);
767
    if ($index > $stringy->length()) {
768
      return $stringy;
769
    }
770
771
    $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
772
    $end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding);
773
774
    $stringy->str = $start . $substring . $end;
775
776
    return $stringy;
777
  }
778
779
  /**
780
   * Returns true if the string contains only alphabetic chars, false
781
   * otherwise.
782
   *
783
   * @return bool Whether or not $str contains only alphabetic chars
@@ 2066-2081 (lines=16) @@
2063
   *
2064
   * @return Stringy Object with the resulting $str after truncating
2065
   */
2066
  public function truncate($length, $substring = '')
2067
  {
2068
    $stringy = static::create($this->str, $this->encoding);
2069
    if ($length >= $stringy->length()) {
2070
      return $stringy;
2071
    }
2072
2073
    // Need to further trim the string so we can append the substring
2074
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
2075
    $length -= $substringLength;
2076
2077
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2078
    $stringy->str = $truncated . $substring;
2079
2080
    return $stringy;
2081
  }
2082
2083
  /**
2084
   * Returns a lowercase and trimmed string separated by underscores.