Code Duplication    Length = 16-17 lines in 2 locations

src/Stringy.php 2 locations

@@ 789-805 (lines=17) @@
786
   *
787
   * @return static  Object with the resulting $str after the insertion
788
   */
789
  public function insert($substring, $index)
790
  {
791
    $stringy = static::create($this->str, $this->encoding);
792
    if ($index > $stringy->length()) {
793
      return $stringy;
794
    }
795
796
    $start = UTF8::substr($stringy->str, 0, $index, $stringy->encoding);
797
    $end = UTF8::substr($stringy->str, $index, $stringy->length(), $stringy->encoding);
798
799
    $stringy->str = $start . $substring . $end;
800
801
    return $stringy;
802
  }
803
804
  /**
805
   * Returns true if the string contains the $pattern, otherwise false.
806
   *
807
   * WARNING: Asterisks ("*") are translated into (".*") zero-or-more regular
808
   * expression wildcards.
@@ 2126-2141 (lines=16) @@
2123
   *
2124
   * @return static  Object with the resulting $str after truncating
2125
   */
2126
  public function truncate($length, $substring = '')
2127
  {
2128
    $stringy = static::create($this->str, $this->encoding);
2129
    if ($length >= $stringy->length()) {
2130
      return $stringy;
2131
    }
2132
2133
    // Need to further trim the string so we can append the substring
2134
    $substringLength = UTF8::strlen($substring, $stringy->encoding);
2135
    $length -= $substringLength;
2136
2137
    $truncated = UTF8::substr($stringy->str, 0, $length, $stringy->encoding);
2138
    $stringy->str = $truncated . $substring;
2139
2140
    return $stringy;
2141
  }
2142
2143
  /**
2144
   * Returns a lowercase and trimmed string separated by underscores.