Skip to content

Commit

Permalink
Allow defaulting end parameter to start value in findBetween
Browse files Browse the repository at this point in the history
  • Loading branch information
salehhashemi1992 committed Nov 2, 2023
1 parent aa9adc8 commit 67bb299
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions framework/helpers/BaseStringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -529,17 +529,22 @@ public static function mask($string, $start, $length, $mask = '*') {
}

/**
* Returns the portion of the string that lies between the first occurrence of the start string
* and the last occurrence of the end string after that.
* Returns the portion of the string that lies between the first occurrence of the `$start` string
* and the last occurrence of the `$end` string after that.
*
* @param string $string The input string.
* @param string $start The string marking the start of the portion to extract.
* @param string $end The string marking the end of the portion to extract.
* @param string|null $end The string marking the end of the portion to extract.
* If the `$end` string is not provided, it defaults to the value of the `$start` string.
* @return string|null The portion of the string between the first occurrence of
* start and the last occurrence of end, or null if either start or end cannot be found.
* `$start` and the last occurrence of `$end`, or null if either `$start` or `$end` cannot be found.
*/
public static function findBetween($string, $start, $end)
{
if ($end === null) {
$end = $start;

Check warning on line 545 in framework/helpers/BaseStringHelper.php

View check run for this annotation

Codecov / codecov/patch

framework/helpers/BaseStringHelper.php#L545

Added line #L545 was not covered by tests
}

$startPos = mb_strpos($string, $start);

if ($startPos === false) {
Expand Down

0 comments on commit 67bb299

Please sign in to comment.