create(ParserFactory::PREFER_PHP7); CODE_SAMPLE , <<<'CODE_SAMPLE' use PhpParser\ParserFactory; $factory = new ParserFactory; $parser = $factory->createForNewestSupportedVersion(); CODE_SAMPLE )]); } /** * @return array> */ public function getNodeTypes() : array { return [MethodCall::class]; } /** * @param MethodCall $node */ public function refactor(Node $node) : ?Node { if (!$this->isObjectType($node->var, new ObjectType('PhpParser\\ParserFactory'))) { return null; } if (!$this->isName($node->name, 'create')) { return null; } $args = $node->getArgs(); $value = $this->valueResolver->getValue($args[0]->value); if ($value === 1) { $node->name = new Identifier('createForNewestSupportedVersion'); $node->args = []; return $node; } if ($value === 4) { $node->name = new Identifier('createForVersion'); $fullyQualified = new FullyQualified('PhpParser\\PhpVersion'); $fromStringStaticCall = new StaticCall($fullyQualified, 'fromString', [new Arg(new String_('5.6'))]); $node->args = [new Arg($fromStringStaticCall)]; return $node; } return null; } }