Use generators for tests for MDNodaRepository validation
This commit is contained in:
@@ -442,6 +442,9 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
if (str_contains($id, '(')) {
|
||||
$id = trim(explode('(', $id)[0]);
|
||||
}
|
||||
if (str_contains($id, PHP_EOL)) {
|
||||
$id = trim(explode(PHP_EOL, $id)[0]);
|
||||
}
|
||||
|
||||
// There is an issue with this regex
|
||||
if (preg_match("/^[0-9-X]*$/", $id) === false) {
|
||||
@@ -630,7 +633,10 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
private static function validateNpgId(string $id):string|false {
|
||||
|
||||
if (filter_var($id, FILTER_VALIDATE_URL) !== false) {
|
||||
$id = strtr($id, ['https://www.npg.org.uk/collections/search/person/' => '']);
|
||||
$id = strtr($id, [
|
||||
'http://www.npg.org.uk/collections/search/person/' => '',
|
||||
'https://www.npg.org.uk/collections/search/person/' => '',
|
||||
]);
|
||||
}
|
||||
|
||||
if (substr($id, 0, 2) === 'mp' && self::_is_numeric(substr($id, 2))) {
|
||||
@@ -658,15 +664,18 @@ enum MDNodaRepository implements MDValueEnumInterface, JsonSerializable {
|
||||
$id = strtr($id, [
|
||||
'http://www.wikidata.org/wiki/' => '',
|
||||
'http://www.wikidata.org/entity/' => '',
|
||||
'http://www.wikidata.org/w/index.php?search=&search=' => '',
|
||||
'https://www.wikidata.org/wiki/' => '',
|
||||
'https://www.wikidata.org/entity/' => '',
|
||||
'https://www.wikidata.org/w/index.php?search=&search=' => '',
|
||||
]);
|
||||
|
||||
if (str_starts_with($id, 'https://www.wikidata.org/w/index.php?title=')) {
|
||||
$id = str_replace('https://www.wikidata.org/w/index.php?title=', '', $id);
|
||||
if (($endPos = strpos($id, '&')) !== false) {
|
||||
$id = substr($id, 0, $endPos);
|
||||
foreach (['http://www.wikidata.org/w/index.php?title=', 'https://www.wikidata.org/w/index.php?title='] as $urlPrefix) {
|
||||
if (str_starts_with($id, $urlPrefix)) {
|
||||
$id = str_replace($urlPrefix, '', $id);
|
||||
if (($endPos = strpos($id, '&')) !== false) {
|
||||
$id = substr($id, 0, $endPos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user