Skip to content

Commit

Permalink
[Php70] Fix with \r\n on EregToPregMatchRector (#6246)
Browse files Browse the repository at this point in the history
* Add CRLF test case for EregToPregMatchRector

* Closes #6245

* Closes #6245

---------

Co-authored-by: Michael McEniry <mcenirm@mceniry.net>
  • Loading branch information
samsonasik and mcenirm committed Aug 21, 2024
1 parent 98f6159 commit c3f5cbc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ function eregToPregMatch3()
split('hi', 'hi, she said', 0);

spliti('hi', 'hi, she said', 1);

split("\r\n", "line 1\r\nline 2\r\n");
}

?>
Expand All @@ -24,6 +26,8 @@ function eregToPregMatch3()
preg_split('#hi#m', 'hi, she said', 1);

preg_split('#hi#mi', 'hi, she said', 1);

preg_split("#\r\n#m", "line 1\r\nline 2\r\n");
}

?>
4 changes: 3 additions & 1 deletion rules/Php70/Rector/FuncCall/EregToPregMatchRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;

/**
* @see \Rector\Tests\Php70\Rector\FuncCall\EregToPregMatchRector\EregToPregMatchRectorTest
Expand Down Expand Up @@ -111,7 +112,8 @@ private function processStringPattern(FuncCall $funcCall, String_ $string, strin
$pattern = $this->eregToPcreTransformer->transform($pattern, $this->isCaseInsensitiveFunction($functionName));

$firstArg = $funcCall->getArgs()[0];
$firstArg->value = new String_($pattern);
Assert::isInstanceOf($firstArg->value, String_::class);
$firstArg->value->value = $pattern;
}

private function processVariablePattern(FuncCall $funcCall, Variable $variable, string $functionName): void
Expand Down

0 comments on commit c3f5cbc

Please sign in to comment.