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