Code Duplication    Length = 14-16 lines in 2 locations

src/Stringy.php 2 locations

@@ 918-931 (lines=14) @@
915
   *
916
   * @return static <p>Object with the resulting $str after the insertion.</p>
917
   */
918
  public function insert(string $substring, int $index): Stringy
919
  {
920
    $stringy = static::create($this->str, $this->encoding);
921
    if ($index > $stringy->length()) {
922
      return $stringy;
923
    }
924
925
    $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
926
    $end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding);
927
928
    $stringy->str = $start . $substring . $end;
929
930
    return $stringy;
931
  }
932
933
  /**
934
   * Returns true if the string contains the $pattern, otherwise false.
@@ 2341-2356 (lines=16) @@
2338
   *
2339
   * @return static <p>Object with the resulting $str after truncating.</p>
2340
   */
2341
  public function truncate(int $length, string $substring = ''): Stringy
2342
  {
2343
    $stringy = static::create($this->str, $this->encoding);
2344
    if ($length >= $stringy->length()) {
2345
      return $stringy;
2346
    }
2347
2348
    // Need to further trim the string so we can append the substring
2349
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
2350
    $length -= $substringLength;
2351
2352
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2353
    $stringy->str = $truncated . $substring;
2354
2355
    return $stringy;
2356
  }
2357
2358
  /**
2359
   * Returns a lowercase and trimmed string separated by underscores.