Add blacklist for invalid damage types

This commit is contained in:
Joshua Ramon Enslin 2023-11-22 13:38:57 +01:00
parent 881a3d6c9c
commit 016245722a
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE
2 changed files with 27 additions and 0 deletions

View File

@ -0,0 +1,18 @@
<?PHP
declare(strict_types = 1);
/**
* Exception thrown in case a requested concordance term is blacklisted.
*/
final class MDImporterBlacklistedConcordanceTerm extends Exception {
/**
* Error message.
*
* @return string
*/
public function errorMessage() {
//error message
return 'Blacklisted term requested for concordance list.';
}
}

View File

@ -18,6 +18,10 @@ final class MDConcDamageTypes implements MDImporterConcordanceListInterface {
"Desiccation" => MDObjectDamageType::desiccation,
];
private const DAMAGE_TYPES_BLACKLIST = [
'keine',
];
/**
* Require a function for getting the concordance target.
*
@ -28,6 +32,11 @@ final class MDConcDamageTypes implements MDImporterConcordanceListInterface {
public static function getConcordanceTarget(string $input):MDObjectDamageType {
if (!isset(self::DAMAGE_TYPES[$input])) {
if (in_array($input, self::DAMAGE_TYPES_BLACKLIST, true)) {
throw new MDImporterBlacklistedConcordanceTerm("Invalid damage type: " . $input);
}
throw new MDImporterMissingConcordance("Unknown damage type: " . $input);
}