Example #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $project = $input->getOption('project');
     /**
      * @var \JMOlivas\Phpqa\Console\Application $application
      */
     $application = $this->getApplication();
     /**
      * @var \JMOlivas\Phpqa\Config $config
      */
     $config = $application->getConfig();
     if (!$config->isCustom() && !$project) {
         throw new Exception(sprintf('No local phpqa.yml or phpqa.yml.dist at current working directory ' . 'you must provide a valid project value (%s)', implode(',', $this->projects)));
     }
     if (!$config->isCustom() && !in_array($project, $this->projects)) {
         throw new Exception(sprintf('You must provide a valid project value (%s)', implode(',', $this->projects)));
     }
     $config->loadProjectConfiguration($project);
     $this->directory = $application->getApplicationDirectory();
     $output->writeln(sprintf('<question>%s</question>', $application->getName()));
     $filesOption = new FilesOption($input->getOption('files'));
     $git = $input->getOption('git');
     if (!$filesOption->isAbsent() && $git) {
         throw new Exception('Options `files` and `git` cannot be used in combination.');
     }
     if ($filesOption->isAbsent() && !$git) {
         throw new Exception('You must set `files` or `git` options.');
     }
     if (!$filesOption->isAbsent() && $filesOption->isEmpty()) {
         throw new Exception('Options `files` needs at least one file.');
     }
     if ($git) {
         $files = $this->extractCommitedFiles($output, $config);
     } else {
         $files = $filesOption->normalize();
     }
     $output->writeln(sprintf('<info>%s</info>', $config->get('application.messages.files.info')));
     foreach ($files as $file) {
         $output->writeln(sprintf('<comment> - %s</comment>', $file));
     }
     $this->checkComposer($output, $files, $config);
     $analyzers = array_keys($config->get('application.analyzer'));
     foreach ($analyzers as $analyzer) {
         $this->analyzer($output, $analyzer, $files, $config, $project);
     }
     $output->writeln(sprintf('<info>%s</info>', $config->get('application.messages.completed.info')));
 }
Example #2
0
 /** @test */
 function it_should_return_empty_array_if_input_is_empty()
 {
     $emptyInput = [null];
     $files = new FilesOption($emptyInput);
     $this->assertCount(0, $files->normalize());
 }