Skip to content
This repository has been archived by the owner on Sep 24, 2020. It is now read-only.

Commit

Permalink
CheckCommand - read parser level from Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Jan 5, 2017
1 parent f4606a3 commit adf7a10
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions src/Command/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,34 @@ protected function execute(InputInterface $input, OutputInterface $output)
$output->writeln('<error>It is highly recommended to disable the XDebug extension before invoking this command.</error>');
}

$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',
Expand All @@ -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);
Expand Down

0 comments on commit adf7a10

Please sign in to comment.