[PHP 5.5] Prevent error on non-string value in PregReplaceEModifierRector

This commit is contained in:
TomasVotruba 2020-03-25 13:42:33 +01:00
parent 47a19ac620
commit b113c38670
2 changed files with 17 additions and 1 deletions

View File

@ -87,7 +87,12 @@ PHP
return null;
}
$pattern = $this->getValue($node->args[0]->value);
$firstArgumentValue = $node->args[0]->value;
if (! $firstArgumentValue instanceof String_) {
return null;
}
$pattern = $this->getValue($firstArgumentValue);
$delimiter = $pattern[0];
/** @var string $modifiers */

View File

@ -0,0 +1,11 @@
<?php
namespace Rector\Php55\Tests\Rector\FuncCall\PregReplaceEModifierRector\Fixture;
class SkipNonString
{
public function run($contents)
{
$contents = preg_replace(['/\s+$/Sm', '/\n+/S'], "\n", $contents);
}
}