From b945939d407f8c713c56567e4a2e8d6cbbabb4ea Mon Sep 17 00:00:00 2001 From: lowerends Date: Thu, 27 Aug 2015 17:06:32 +0200 Subject: [PATCH] Added exception handling This exception handling will handle timeouts in the service. --- src/Console/CheckCommand.php | 44 +++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/Console/CheckCommand.php b/src/Console/CheckCommand.php index b85a41f..47113e4 100644 --- a/src/Console/CheckCommand.php +++ b/src/Console/CheckCommand.php @@ -2,6 +2,7 @@ use Illuminate\Console\Command; use SensioLabs\Security\SecurityChecker; +use SensioLabs\Security\Exception\RuntimeException; class CheckCommand extends Command { @@ -18,37 +19,44 @@ public function fire() { $checker = new SecurityChecker(); - $alerts = $checker->check(base_path() . '/composer.lock'); - - if (!empty($alerts)) + try { - foreach ($alerts as $package => $alert) + $alerts = $checker->check(base_path() . '/composer.lock'); + + if (!empty($alerts)) { - $this->error('Security advisories found!'); + foreach ($alerts as $package => $alert) + { + $this->error('Security advisories found!'); - $this->info('======================'); + $this->info('======================'); - $this->info('Package: ' . $package); + $this->info('Package: ' . $package); - foreach ($alert['advisories'] as $advisory) - { - $this->info('Version: ' . $alert['version']); + foreach ($alert['advisories'] as $advisory) + { + $this->info('Version: ' . $alert['version']); - $this->info('Title: ' . $advisory['title']); + $this->info('Title: ' . $advisory['title']); - $this->info('Link: ' . $advisory['link']); + $this->info('Link: ' . $advisory['link']); - if($advisory['cve'] != "") - { - $this->info('CVE: ' . $advisory['cve']); + if($advisory['cve'] != "") + { + $this->info('CVE: ' . $advisory['cve']); + } } } - } + } + else + { + $this->info('No security advisories found!'); + } } - else + catch (RuntimeException $e) { - $this->info('No security advisories found!'); + $this->error('Security check failed: ' . $e->getMessage()); } } }