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 the $pattern, otherwise false.
781
   *
782
   * WARNING: Asterisks ("*") are translated into (".*") zero-or-more regular
783
   * expression wildcards.
@@ 2090-2105 (lines=16) @@
2087
   *
2088
   * @return Stringy Object with the resulting $str after truncating
2089
   */
2090
  public function truncate($length, $substring = '')
2091
  {
2092
    $stringy = static::create($this->str, $this->encoding);
2093
    if ($length >= $stringy->length()) {
2094
      return $stringy;
2095
    }
2096
2097
    // Need to further trim the string so we can append the substring
2098
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
2099
    $length -= $substringLength;
2100
2101
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2102
    $stringy->str = $truncated . $substring;
2103
2104
    return $stringy;
2105
  }
2106
2107
  /**
2108
   * Returns a lowercase and trimmed string separated by underscores.