Skip to content
This repository has been archived by the owner on Jan 15, 2021. It is now read-only.

Commit

Permalink
refactored the previous merge to avoid breaking BC
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Apr 25, 2013
1 parent db3b8c5 commit edb9441
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 26 deletions.
9 changes: 4 additions & 5 deletions SensioLabs/Security/Command/SecurityCheckerCommand.php
Expand Up @@ -12,7 +12,6 @@
namespace SensioLabs\Security\Command;

use SensioLabs\Security\SecurityChecker;
use SensioLabs\Security\SecurityException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -64,16 +63,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
try {
$data = $this->checker->check($input->getArgument('lock'), $input->getOption('format'));
} catch (SecurityException $e) {
$output->write($e->getMessage());

return 1;
} catch (\Exception $e) {
$output->writeln($this->getHelperSet()->get('formatter')->formatBlock($e->getMessage(), 'error', true));

return 1;
}

$output->write($data);

if ($this->checker->getLastVulnerabilityCount() > 0) {
return 1;
}
}
}
12 changes: 8 additions & 4 deletions SensioLabs/Security/SecurityChecker.php
Expand Up @@ -13,6 +13,8 @@

class SecurityChecker
{
private $vulnerabilitiesCount;

/**
* Checks a composer.lock file.
*
Expand Down Expand Up @@ -109,11 +111,13 @@ public function check($lock, $format = 'text')
throw new \RuntimeException('The web service did not return alerts count');
}

$vulnerabilitiesCount = intval($matches[1]);
if ($vulnerabilitiesCount > 0) {
throw new SecurityException($body, $vulnerabilitiesCount);
}
$this->vulnerabilitiesCount = intval($matches[1]);

return $body;
}

public function getLastVulnerabilityCount()
{
return $this->vulnerabilitiesCount;
}
}
17 changes: 0 additions & 17 deletions SensioLabs/Security/SecurityException.php

This file was deleted.

0 comments on commit edb9441

Please sign in to comment.