protected function execute(InputInterface $input, OutputInterface $output) { $projectUuid = $input->getArgument('project-uuid'); $api = $this->getApplication()->getApi(); $analysis = $api->analyze($projectUuid, $input->getOption('reference')); $chars = array('-', '\\', '|', '/'); $position = 0; while (true) { // we don't check the status too often if (0 == $position % 2) { $analysis = $api->getAnalysisStatus($projectUuid, $analysis->getNumber()); } if ('txt' === $input->getOption('format')) { $output->write(sprintf("%s %-80s\r", $chars[$position % 4], $analysis->getStatusMessage())); } if ($analysis->isFinished()) { break; } usleep(200000); ++$position; } $analysis = $api->getAnalysis($projectUuid, $analysis->getNumber()); if ($analysis->isFailed()) { $output->writeln(sprintf('There was an error: "%s"', $analysis->getFailureMessage())); return 1; } $helper = new DescriptorHelper($api->getSerializer()); $helper->describe($output, $analysis, $input->getOption('format'), $input->getOption('show-ignored-violations')); if ('txt' === $input->getOption('format') && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { $output->writeln(''); $output->writeln(sprintf('Run <comment>%s %s %s -v</comment> to get the full report', $_SERVER['PHP_SELF'], 'analysis', $projectUuid)); } }
protected function execute(InputInterface $input, OutputInterface $output) { $api = $this->getApplication()->getApi(); $analysis = $api->getProject($input->getArgument('project-uuid'))->getLastAnalysis(); if (!$analysis) { $output->writeln('<error>There are no analyses</error>'); return 1; } $helper = new DescriptorHelper($api->getSerializer()); $helper->describe($output, $analysis, $input->getOption('format')); if ('txt' === $input->getOption('format') && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { $output->writeln(''); $output->writeln('Re-run this command with <comment>-v</comment> option to get the full report'); } if (!($expr = $input->getOption('fail-condition'))) { return; } $el = new ExpressionLanguage(); $counts = array(); foreach ($analysis->getViolations() as $violation) { if (!isset($counts[$violation->getCategory()])) { $counts[$violation->getCategory()] = 0; } ++$counts[$violation->getCategory()]; if (!isset($counts[$violation->getSeverity()])) { $counts[$violation->getSeverity()] = 0; } ++$counts[$violation->getSeverity()]; } $vars = array('analysis' => $analysis, 'counts' => (object) $counts); if ($el->evaluate($expr, $vars)) { return 70; } }