Code Duplication    Length = 16-17 lines in 2 locations

src/Stringy.php 2 locations

@@ 827-843 (lines=17) @@
824
   *
825
   * @return static  Object with the resulting $str after the insertion
826
   */
827
  public function insert($substring, $index)
828
  {
829
    $stringy = static::create($this->str, $this->encoding);
830
    if ($index > $stringy->length()) {
831
      return $stringy;
832
    }
833
834
    $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
835
    $end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding);
836
837
    $stringy->str = $start . $substring . $end;
838
839
    return $stringy;
840
  }
841
842
  /**
843
   * Returns true if the string contains the $pattern, otherwise false.
844
   *
845
   * WARNING: Asterisks ("*") are translated into (".*") zero-or-more regular
846
   * expression wildcards.
@@ 2253-2268 (lines=16) @@
2250
   *
2251
   * @return static  Object with the resulting $str after truncating
2252
   */
2253
  public function truncate($length, $substring = '')
2254
  {
2255
    $stringy = static::create($this->str, $this->encoding);
2256
    if ($length >= $stringy->length()) {
2257
      return $stringy;
2258
    }
2259
2260
    // Need to further trim the string so we can append the substring
2261
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
2262
    $length -= $substringLength;
2263
2264
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2265
    $stringy->str = $truncated . $substring;
2266
2267
    return $stringy;
2268
  }
2269
2270
  /**
2271
   * Returns a lowercase and trimmed string separated by underscores.