refactor: Detach – toter Zweig, benannte Argumente; VariableDetachRewrite-Docblock nennt leftover()

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-19 14:40:50 +02:00
co-authored by Claude Sonnet 5.5
parent 7608be6558
commit 5064409f9a
2 changed files with 20 additions and 20 deletions
@@ -256,17 +256,17 @@ final class DiviDesignDetachAbility implements Ability, RequiresDiviFeatures
} }
return new DetachTarget( return new DetachTarget(
sprintf('Variable „%s“', $label), subject: sprintf('Variable „%s“', $label),
$postIds, postIds: $postIds,
new ReferenceUsageQuery([$id]), query: new ReferenceUsageQuery([$id]),
fn (): NodeRewrite => new VariableDetachRewrite($id, $value, $type, ($this->unfiltered)()), rewrite: fn (): NodeRewrite => new VariableDetachRewrite($id, $value, $type, ($this->unfiltered)()),
$nested presets: $nested
? static fn (PresetBook $presets): PresetBook => $presets->withVariableResolved($id, $value, $affixes) ? static fn (PresetBook $presets): PresetBook => $presets->withVariableResolved($id, $value, $affixes)
: null, : null,
'Presets', nestedIn: 'Presets',
$notes, notes: $notes,
self::ARCHIVE_HINT, doneHint: self::ARCHIVE_HINT,
$notes === [] complete: $notes === []
); );
} }
@@ -278,7 +278,7 @@ final class DiviDesignDetachAbility implements Ability, RequiresDiviFeatures
{ {
$problem = match (true) { $problem = match (true) {
$value === '' => 'ist leer', $value === '' => 'ist leer',
VariableDetachRewrite::unsafe($value, true) => 'enthält einen Verweis', VariableDetachRewrite::unsafe($value, markupAllowed: true) => 'enthält einen Verweis',
VariableDetachRewrite::unsafe($value, ($this->unfiltered)()) => 'enthält Markup (< oder >), das dieses ' VariableDetachRewrite::unsafe($value, ($this->unfiltered)()) => 'enthält Markup (< oder >), das dieses '
. 'Konto nicht speichern darf (unfiltered_html)', . 'Konto nicht speichern darf (unfiltered_html)',
default => null, default => null,
@@ -336,15 +336,15 @@ final class DiviDesignDetachAbility implements Ability, RequiresDiviFeatures
$nested = $postIds === null && $book->nestedUsers($id) !== []; $nested = $postIds === null && $book->nestedUsers($id) !== [];
return new DetachTarget( return new DetachTarget(
sprintf('%s „%s“', $scope->label(), $label), subject: sprintf('%s „%s“', $scope->label(), $label),
$postIds, postIds: $postIds,
// Explicit references only (R10), also for a default preset: no withGroups(), implicit uses stay. // Explicit references only (R10), also for a default preset: no withGroups(), implicit uses stay.
new PresetUsageQuery([['scope' => $scope, 'id' => $id, 'default' => false]]), query: new PresetUsageQuery([['scope' => $scope, 'id' => $id, 'default' => false]]),
static fn (): NodeRewrite => new DetachRewrite($scope, $id), rewrite: static fn (): NodeRewrite => new DetachRewrite($scope, $id),
$nested ? static fn (PresetBook $presets): PresetBook => $presets->withoutNestedRef($id) : null, presets: $nested ? static fn (PresetBook $presets): PresetBook => $presets->withoutNestedRef($id) : null,
'anderen Presets', nestedIn: 'anderen Presets',
$book->defaultId($scope) === $id ? [sprintf(self::DEFAULT_NOTE, $label, $scope->name)] : [], notes: $book->defaultId($scope) === $id ? [sprintf(self::DEFAULT_NOTE, $label, $scope->name)] : [],
self::DELETE_HINT doneHint: self::DELETE_HINT
); );
} }
@@ -420,7 +420,7 @@ final class DiviDesignDetachAbility implements Ability, RequiresDiviFeatures
{ {
return function (array $raw) use ($target): DesignPlan|WP_Error { return function (array $raw) use ($target): DesignPlan|WP_Error {
$before = PresetBook::fromDivi($raw); $before = PresetBook::fromDivi($raw);
$after = $target->presets === null ? $before : ($target->presets)($before); $after = ($target->presets)($before);
$diff = PresetDiff::between($before, $after); $diff = PresetDiff::between($before, $after);
if ($diff === []) { if ($diff === []) {
return new DesignPlan($after->data(), [], PresetDiff::summary([])); return new DesignPlan($after->data(), [], PresetDiff::summary([]));
@@ -14,7 +14,7 @@ defined('ABSPATH') || exit;
* with variable, ruling V9): every attribute value that is exactly one reference $variable({"type":"content", * with variable, ruling V9): every attribute value that is exactly one reference $variable({"type":"content",
* "value":{"name":"<id>",…}})$ becomes the value – for a strings variable with the reference's own before/after * "value":{"name":"<id>",…}})$ becomes the value – for a strings variable with the reference's own before/after
* around it. References embedded in a longer text stay (Divi resolves them inside the text; cutting them out would * around it. References embedded in a longer text stay (Divi resolves them inside the text; cutting them out would
* change the text) and are named in notes(). Other references – colors, other variables, dynamic content – stay * change the text) and are reported through leftover() (ReportsLeftovers). Other references – colors, other variables, dynamic content – stay
* untouched. Pure PHP. * untouched. Pure PHP.
*/ */
final class VariableDetachRewrite implements NodeRewrite, ReportsLeftovers final class VariableDetachRewrite implements NodeRewrite, ReportsLeftovers