2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Describes the severity of an @{class:ArcanistLintMessage}.
|
|
|
|
*
|
|
|
|
* @group lint
|
|
|
|
*/
|
2012-01-31 21:07:05 +01:00
|
|
|
final class ArcanistLintSeverity {
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
const SEVERITY_ADVICE = 'advice';
|
2012-04-06 21:23:19 +02:00
|
|
|
const SEVERITY_AUTOFIX = 'autofix';
|
2011-01-10 00:22:25 +01:00
|
|
|
const SEVERITY_WARNING = 'warning';
|
|
|
|
const SEVERITY_ERROR = 'error';
|
|
|
|
const SEVERITY_DISABLED = 'disabled';
|
|
|
|
|
|
|
|
public static function getStringForSeverity($severity_code) {
|
|
|
|
static $map = array(
|
|
|
|
self::SEVERITY_ADVICE => 'Advice',
|
2012-04-06 21:23:19 +02:00
|
|
|
self::SEVERITY_AUTOFIX => 'Auto-Fix',
|
2011-01-10 00:22:25 +01:00
|
|
|
self::SEVERITY_WARNING => 'Warning',
|
|
|
|
self::SEVERITY_ERROR => 'Error',
|
|
|
|
self::SEVERITY_DISABLED => 'Disabled',
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!array_key_exists($severity_code, $map)) {
|
|
|
|
throw new Exception("Unknown lint severity '{$severity_code}'!");
|
|
|
|
}
|
|
|
|
|
|
|
|
return $map[$severity_code];
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function isAtLeastAsSevere(
|
|
|
|
ArcanistLintMessage $message,
|
|
|
|
$level) {
|
|
|
|
|
|
|
|
static $map = array(
|
|
|
|
self::SEVERITY_DISABLED => 10,
|
|
|
|
self::SEVERITY_ADVICE => 20,
|
2012-04-06 21:23:19 +02:00
|
|
|
self::SEVERITY_AUTOFIX => 25,
|
2011-01-10 00:22:25 +01:00
|
|
|
self::SEVERITY_WARNING => 30,
|
|
|
|
self::SEVERITY_ERROR => 40,
|
|
|
|
);
|
|
|
|
|
|
|
|
$message_sev = $message->getSeverity();
|
|
|
|
if (empty($map[$message_sev])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $map[$message_sev] >= idx($map, $level, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|