/** * @see Command * @see SecurityChecker */ protected function execute(InputInterface $input, OutputInterface $output) { if ($endPoint = $input->getOption('end-point')) { $this->checker->getCrawler()->setEndPoint($endPoint); } if ($timeout = $input->getOption('timeout')) { $this->checker->getCrawler()->setTimeout($timeout); } try { $vulnerabilities = $this->checker->check($input->getArgument('lockfile')); } catch (ExceptionInterface $e) { $output->writeln($this->getHelperSet()->get('formatter')->formatBlock($e->getMessage(), 'error', true)); return 1; } switch ($input->getOption('format')) { case 'json': $formatter = new JsonFormatter(); break; case 'simple': $formatter = new SimpleFormatter($this->getHelperSet()->get('formatter')); break; case 'text': default: $formatter = new TextFormatter($this->getHelperSet()->get('formatter')); } $formatter->displayResults($output, $input->getArgument('lockfile'), $vulnerabilities); if ($this->checker->getLastVulnerabilityCount() > 0) { return 1; } }
/** * @throws \Exception */ public function handle() { \Log::info('QA::COMPOSER-SECURITY Run composer security checker'); $checker = new SecurityChecker(); $alerts = $checker->check('composer.lock'); if ($alerts !== false && !empty($alerts)) { $formatter = new TextFormatter($this->getHelperSet()->get('formatter')); $formatter->displayResults($this->output, 'composer.lock', $alerts); throw new \Exception('Vulnerability detected'); } $this->info("No vulnerability detected"); }