1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2025-01-09 06:11:01 +01:00
phorge-arcanist/src/lint/ArcanistLintSeverity.php

51 lines
1.3 KiB
PHP
Raw Normal View History

2011-01-10 00:22:25 +01:00
<?php
/**
* Describes the severity of an @{class:ArcanistLintMessage}.
*/
final class ArcanistLintSeverity extends Phobject {
2011-01-10 00:22:25 +01:00
const SEVERITY_ADVICE = 'advice';
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 getLintSeverities() {
return array(
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
);
}
public static function getStringForSeverity($severity_code) {
$map = self::getLintSeverities();
2011-01-10 00:22:25 +01:00
if (!array_key_exists($severity_code, $map)) {
throw new Exception(pht("Unknown lint severity '%s'!", $severity_code));
2011-01-10 00:22:25 +01:00
}
return $map[$severity_code];
}
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,
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);
}
}