2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Describes the severity of an @{class:ArcanistLintMessage}.
|
|
|
|
*/
|
2015-06-15 07:45:13 +02:00
|
|
|
final class ArcanistLintSeverity extends Phobject {
|
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';
|
|
|
|
|
2012-11-09 04:29:40 +01:00
|
|
|
public static function getLintSeverities() {
|
|
|
|
return array(
|
2015-05-13 10:05:15 +02: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-10 00:22:25 +01:00
|
|
|
);
|
2012-11-09 04:29:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function getStringForSeverity($severity_code) {
|
|
|
|
$map = self::getLintSeverities();
|
2011-01-10 00:22:25 +01:00
|
|
|
|
|
|
|
if (!array_key_exists($severity_code, $map)) {
|
2015-05-13 10:05:15 +02:00
|
|
|
throw new Exception(pht("Unknown lint severity '%s'!", $severity_code));
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return $map[$severity_code];
|
|
|
|
}
|
|
|
|
|
2013-02-15 00:18:39 +01:00
|
|
|
public static function isAtLeastAsSevere($message_sev, $level) {
|
2011-01-10 00:22:25 +01:00
|
|
|
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,
|
|
|
|
);
|
|
|
|
|
|
|
|
if (empty($map[$message_sev])) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $map[$message_sev] >= idx($map, $level, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|