refactor: FontNameRules::check() ohne toten Reserviert-Zweig; Kollision bleibt taken()/409

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-19 18:28:23 +02:00
co-authored by Claude Sonnet 5.5
parent bfe6623fe8
commit 15cffedb9f
4 changed files with 29 additions and 30 deletions
@@ -160,9 +160,7 @@ final class DiviFontsUploadAbility implements Ability, RequiresDiviFeatures
}
$name = is_string($input['name'] ?? null) ? $input['name'] : '';
$taken = FontNameRules::taken($name, $this->catalog->reserved());
$nameProblem = $taken === null
? FontNameRules::check($name, [], $this->installer->nameMaxLength())
: null;
$nameProblem = FontNameRules::check($name, $this->installer->nameMaxLength());
if ($nameProblem !== null) {
$errors['name'] = $nameProblem;
}
+5 -10
View File
@@ -23,10 +23,11 @@ final class FontNameRules
private const DIVI_STRIPS = '/[^A-Za-z0-9\s\_-]/';
/**
* @param list<string> $reserved Names of Google, web-safe and uploaded fonts (FontCatalog::reserved()).
* The form only; whether the name is taken is taken().
*
* @return string|null null = valid, else the problem (German).
*/
public static function check(string $name, array $reserved, int $maxLength = self::MAX_LENGTH): ?string
public static function check(string $name, int $maxLength = self::MAX_LENGTH): ?string
{
if (trim($name) === '') {
return sprintf('Name fehlt (1–%d Zeichen)', $maxLength);
@@ -47,17 +48,11 @@ final class FontNameRules
return sprintf('höchstens %d Zeichen (%d angegeben)', $maxLength, strlen($name));
}
$taken = self::taken($name, $reserved);
return $taken === null ? null : sprintf(
'„%s“ gibt es schon als Google-, Web-Safe- oder hochgeladene Schrift (ohne Beachtung der '
. 'Groß-/Kleinschreibung)',
$taken
);
return null;
}
/**
* @param list<string> $reserved
* @param list<string> $reserved Names of Google, web-safe and uploaded fonts (FontCatalog::reserved()).
* @return string|null The existing name $name collides with (case-insensitive), null when it is free.
*/
public static function taken(string $name, array $reserved): ?string