diff --git a/src/Command/CheckCommand.php b/src/Command/CheckCommand.php index f0349154..8a4ba702 100644 --- a/src/Command/CheckCommand.php +++ b/src/Command/CheckCommand.php @@ -71,7 +71,34 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('It is highly recommended to disable the XDebug extension before invoking this command.'); } - $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7, new \PhpParser\Lexer\Emulative([ + /** @var Application $application */ + $application = $this->getApplication(); + $application->compiler = new Compiler(); + + $configFile = $input->getOption('config-file') ?: '.phpsa.yml'; + $configDir = realpath($input->getArgument('path')); + $application->configuration = $this->loadConfiguration($configFile, $configDir); + + $parserStr = $application->configuration->getValue('parser', 'prefer-7'); + switch ($parserStr) { + case 'prefer-7': + $languageLevel = ParserFactory::PREFER_PHP7; + break; + case 'prefer-5': + $languageLevel = ParserFactory::PREFER_PHP5; + break; + case 'only-7': + $languageLevel = ParserFactory::ONLY_PHP7; + break; + case 'only-5': + $languageLevel = ParserFactory::ONLY_PHP5; + break; + default: + $languageLevel = ParserFactory::PREFER_PHP7; + break; + } + + $parser = (new ParserFactory())->create($languageLevel, new \PhpParser\Lexer\Emulative([ 'usedAttributes' => [ 'comments', 'startLine', @@ -81,14 +108,6 @@ protected function execute(InputInterface $input, OutputInterface $output) ] ])); - /** @var Application $application */ - $application = $this->getApplication(); - $application->compiler = new Compiler(); - - $configFile = $input->getOption('config-file') ?: '.phpsa.yml'; - $configDir = realpath($input->getArgument('path')); - $application->configuration = $this->loadConfiguration($configFile, $configDir); - $em = EventManager::getInstance(); Analyzer\Factory::factory($em, $application->configuration); $context = new Context($output, $application, $em);