Code Duplication    Length = 16-17 lines in 2 locations

src/Stringy.php 2 locations

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