simplePhpParser = $simplePhpParser; } public function provideMinPhpVersion() : int { return PhpVersionFeature::STRING_IN_ASSERT_ARG; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('String asserts must be passed directly to assert()', [new CodeSample(<<<'CODE_SAMPLE' function nakedAssert() { assert('true === true'); assert("true === true"); } CODE_SAMPLE , <<<'CODE_SAMPLE' function nakedAssert() { assert(true === true); assert(true === true); } CODE_SAMPLE )]); } /** * @return array> */ public function getNodeTypes() : array { return [FuncCall::class]; } /** * @param FuncCall $node */ public function refactor(Node $node) : ?Node { if (!$this->isName($node, 'assert')) { return null; } if ($node->isFirstClassCallable()) { return null; } $firstArg = $node->getArgs()[0]; $firstArgValue = $firstArg->value; if (!$firstArgValue instanceof String_) { return null; } $phpCode = 'value . ';'; $contentStmts = $this->simplePhpParser->parseString($phpCode); if (!isset($contentStmts[0])) { return null; } if (!$contentStmts[0] instanceof Expression) { return null; } $node->args[0] = new Arg($contentStmts[0]->expr); return $node; } }