/** * @dataProvider parsesRegExpCorrectlyProvider */ public function testParsesRegExpCorrectly($regExp, $expectedStartDelimiter, $expectedEndDelimiter, $expectedExpression, $expectedModifiers) { $parsedRegExp = $this->parser->parse($regExp); $this->assertEquals($expectedStartDelimiter, $parsedRegExp->getStartDelimiter()); $this->assertEquals($expectedEndDelimiter, $parsedRegExp->getEndDelimiter()); $this->assertEquals($expectedExpression, $parsedRegExp->getExpression()); $this->assertEquals($expectedModifiers, $parsedRegExp->getModifiers()); }
/** * {@inheritdoc} */ public function enterNode(Node $node) { if (!$this->functionAnalyzer->isFunctionCallByStaticName($node, 'preg_replace')) { return; } /** @var Node\Expr\FuncCall $node */ $regExpPatternArgument = $node->args[0]; if (!$regExpPatternArgument->value instanceof Node\Scalar\String_) { return; } $regExp = $this->regExpParser->parse($regExpPatternArgument->value->value); if ($regExp->hasModifier(static::PREG_REPLACE_EVAL_MODIFIER)) { $this->addContextMessage(sprintf('Removed regular expression modifier "%s" used', static::PREG_REPLACE_EVAL_MODIFIER), $node); } }