From 0115cd578d98ea27148a61640a0cb005c3b0a682 Mon Sep 17 00:00:00 2001 From: Titouan Galopin Date: Tue, 30 May 2017 17:32:47 +0200 Subject: [PATCH] Add default counts to zero for every category/severity --- Cli/Helper/FailConditionHelper.php | 42 ++++++++++++++++++------------ 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/Cli/Helper/FailConditionHelper.php b/Cli/Helper/FailConditionHelper.php index 715043a..ccc6a92 100644 --- a/Cli/Helper/FailConditionHelper.php +++ b/Cli/Helper/FailConditionHelper.php @@ -26,25 +26,33 @@ public function __construct() public function evaluate(Analysis $analysis, $expr) { - $counts = array(); - - $violations = $analysis->getViolations(); - if ($violations) { - foreach ($violations 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()]; - } + $counts = array( + // Category + 'architecture' => 0, + 'bugrisk' => 0, + 'codestyle' => 0, + 'deadcode' => 0, + 'performance' => 0, + 'readability' => 0, + 'security' => 0, + + // Severity + 'critical' => 0, + 'major' => 0, + 'minor' => 0, + 'info' => 0, + ); + + $violations = $analysis->getViolations() ?: array(); + + foreach ($violations as $violation) { + ++$counts[$violation->getCategory()]; + ++$counts[$violation->getSeverity()]; } + $vars = array( - 'analysis' => $analysis, - 'counts' => (object) $counts, + 'analysis' => $analysis, + 'counts' => (object) $counts, ); if ($this->el->evaluate($expr, $vars)) {