Code Duplication    Length = 16-17 lines in 2 locations

src/Stringy.php 2 locations

@@ 920-936 (lines=17) @@
917
   *
918
   * @return static <p>Object with the resulting $str after the insertion.</p>
919
   */
920
  public function insert($substring, $index)
921
  {
922
    $stringy = static::create($this->str, $this->encoding);
923
    if ($index > $stringy->length()) {
924
      return $stringy;
925
    }
926
927
    $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
928
    $end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding);
929
930
    $stringy->str = $start . $substring . $end;
931
932
    return $stringy;
933
  }
934
935
  /**
936
   * Returns true if the string contains the $pattern, otherwise false.
937
   *
938
   * WARNING: Asterisks ("*") are translated into (".*") zero-or-more regular
939
   * expression wildcards.
@@ 2347-2362 (lines=16) @@
2344
   *
2345
   * @return static <p>Object with the resulting $str after truncating.</p>
2346
   */
2347
  public function truncate($length, $substring = '')
2348
  {
2349
    $stringy = static::create($this->str, $this->encoding);
2350
    if ($length >= $stringy->length()) {
2351
      return $stringy;
2352
    }
2353
2354
    // Need to further trim the string so we can append the substring
2355
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
2356
    $length -= $substringLength;
2357
2358
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2359
    $stringy->str = $truncated . $substring;
2360
2361
    return $stringy;
2362
  }
2363
2364
  /**
2365
   * Returns a lowercase and trimmed string separated by underscores.