Improve matching weights
This commit is contained in:
1 file changed
+26
-2
+26
-2
@@ -10,14 +10,15 @@ declare(strict_types = 1);
|
||||
* Provides lists for categorizing misspelled sizes.
|
||||
*/
|
||||
final class MDConcWeights implements MDImporterConcordanceListInterface {
|
||||
|
||||
/**
|
||||
* Require a function for getting the concordance target.
|
||||
* Matches.
|
||||
*
|
||||
* @param string $input Input string.
|
||||
*
|
||||
* @return MDWeightUnit|false
|
||||
*/
|
||||
public static function getConcordanceTarget(string $input):MDWeightUnit|false {
|
||||
private static function _match(string $input):MDWeightUnit|false {
|
||||
|
||||
return match($input) {
|
||||
|
||||
@@ -34,4 +35,27 @@ final class MDConcWeights implements MDImporterConcordanceListInterface {
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Require a function for getting the concordance target.
|
||||
*
|
||||
* @param string $input Input string.
|
||||
*
|
||||
* @return MDWeightUnit|false
|
||||
*/
|
||||
public static function getConcordanceTarget(string $input):MDWeightUnit|false {
|
||||
|
||||
try {
|
||||
return self::_match($input);
|
||||
}
|
||||
catch (MDInvalidWeightUnit $e) {
|
||||
|
||||
if (is_numeric($input) || is_numeric(strtr($input, ['.' => '', ',' => '']))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return self::_match(trim($input));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user