Skip to content

Commit

Permalink
[Php55] Skip parse error on no concat in left in left Concat on PregR…
Browse files Browse the repository at this point in the history
…eplaceEModifierRector (#6148)

* [Php55] Skip parse error on no concat in left in left Concat on PregReplaceEModifierRector

* [Php55] Skip parse error on no concat in left in left Concat on PregReplaceEModifierRector
  • Loading branch information
samsonasik authored Jul 15, 2024
1 parent 25b437a commit 1e7fffd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\Php55\Rector\FuncCall\PregReplaceEModifierRector\Fixture;

class SkipParseErrorNoConcatLeft
{
public function run($contents)
{
$source_content = preg_replace($search.'e', "'"
. $this->_quote_replace($this->left_delimiter) . 'php'
. "' . str_repeat(\"\n\", substr_count('\\0', \"\n\")) .'"
. $this->_quote_replace($this->right_delimiter)
. "'"
, $source_content);
}
}
5 changes: 5 additions & 0 deletions rules/Php55/RegexMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ private function createPatternWithoutE(string $pattern, string $delimiter, strin

private function matchConcat(Concat $concat): ?Concat
{
// cause parse error
if (! $concat->left instanceof Concat) {
return null;
}

$lastItem = $concat->right;
if (! $lastItem instanceof String_) {
return null;
Expand Down

0 comments on commit 1e7fffd

Please sign in to comment.