Code Duplication    Length = 10-10 lines in 3 locations

src/Stringy.php 3 locations

@@ 296-305 (lines=10) @@
293
   *
294
   * @return static <p>Object with a trimmed $str.</p>
295
   */
296
  public function trim(string $chars = null): self
297
  {
298
    if (!$chars) {
299
      $chars = '[:space:]';
300
    } else {
301
      $chars = \preg_quote($chars, '/');
302
    }
303
304
    return $this->regexReplace("^[$chars]+|[$chars]+\$", '');
305
  }
306
307
  /**
308
   * Replaces all occurrences of $pattern in $str by $replacement.
@@ 2444-2453 (lines=10) @@
2441
   *
2442
   * @return static <p>Object with a trimmed $str.</p>
2443
   */
2444
  public function trimLeft(string $chars = null): self
2445
  {
2446
    if (!$chars) {
2447
      $chars = '[:space:]';
2448
    } else {
2449
      $chars = \preg_quote($chars, '/');
2450
    }
2451
2452
    return $this->regexReplace("^[$chars]+", '');
2453
  }
2454
2455
  /**
2456
   * Returns a string with whitespace removed from the end of the string.
@@ 2464-2473 (lines=10) @@
2461
   *
2462
   * @return static <p>Object with a trimmed $str.</p>
2463
   */
2464
  public function trimRight(string $chars = null): self
2465
  {
2466
    if (!$chars) {
2467
      $chars = '[:space:]';
2468
    } else {
2469
      $chars = \preg_quote($chars, '/');
2470
    }
2471
2472
    return $this->regexReplace("[$chars]+\$", '');
2473
  }
2474
2475
  /**
2476
   * Truncates the string to a given length. If $substring is provided, and