refactor: narrow over-exposed API (L2)
Composer::autoLabel is private (tested through compose()); the DiviComposition getters used only by tests are marked @internal; Limits::snapshotCount is documented as reserved; the ShortformWriter test seam is named $modulesForTests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
@@ -232,7 +232,7 @@ final class Composer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Admin label for a new module: "<Abschnitt> – <Modultitel>" or the title alone. */
|
/** Admin label for a new module: "<Abschnitt> – <Modultitel>" or the title alone. */
|
||||||
public function autoLabel(string $name, string $context): string
|
private function autoLabel(string $name, string $context): string
|
||||||
{
|
{
|
||||||
$title = $this->catalog->title($name);
|
$title = $this->catalog->title($name);
|
||||||
|
|
||||||
|
|||||||
@@ -27,14 +27,14 @@ final class ShortformWriter
|
|||||||
private const COLOR_ERROR = 'Farbe erwartet, z. B. {{color:primary}} oder #1a1a1a';
|
private const COLOR_ERROR = 'Farbe erwartet, z. B. {{color:primary}} oder #1a1a1a';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<string, array<string, array<string, mixed>>>|null $modules Short form per
|
* @param array<string, array<string, array<string, mixed>>>|null $modulesForTests Short form
|
||||||
* type (tests only); null = ShortformMap.
|
* per type, a test seam (trusted wiring only, ledger T2); null = ShortformMap.
|
||||||
*/
|
*/
|
||||||
public function __construct(
|
public function __construct(
|
||||||
private Placeholders $placeholders,
|
private Placeholders $placeholders,
|
||||||
private MediaResolver $media,
|
private MediaResolver $media,
|
||||||
private ValueCleaner $cleaner,
|
private ValueCleaner $cleaner,
|
||||||
private ?array $modules = null
|
private ?array $modulesForTests = null
|
||||||
) {
|
) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ final class ShortformWriter
|
|||||||
{
|
{
|
||||||
// Ruling S35: controls go before placeholder resolution and trim ("{\0{post:title}}").
|
// Ruling S35: controls go before placeholder resolution and trim ("{\0{post:title}}").
|
||||||
$values = ControlChars::stripDeep($values);
|
$values = ControlChars::stripDeep($values);
|
||||||
$fields = $this->modules === null ? ShortformMap::fields($type) : ($this->modules[$type] ?? []);
|
$fields = $this->modulesForTests === null ? ShortformMap::fields($type) : ($this->modulesForTests[$type] ?? []);
|
||||||
$errors = [];
|
$errors = [];
|
||||||
foreach ($values as $name => $value) {
|
foreach ($values as $name => $value) {
|
||||||
$name = (string) $name;
|
$name = (string) $name;
|
||||||
@@ -78,7 +78,7 @@ final class ShortformWriter
|
|||||||
*/
|
*/
|
||||||
public function paths(string $type, array $names): array
|
public function paths(string $type, array $names): array
|
||||||
{
|
{
|
||||||
$fields = $this->modules === null ? ShortformMap::fields($type) : ($this->modules[$type] ?? []);
|
$fields = $this->modulesForTests === null ? ShortformMap::fields($type) : ($this->modulesForTests[$type] ?? []);
|
||||||
$paths = [];
|
$paths = [];
|
||||||
foreach ($names as $name) {
|
foreach ($names as $name) {
|
||||||
if (isset($fields[$name]['path'])) {
|
if (isset($fields[$name]['path'])) {
|
||||||
|
|||||||
@@ -61,7 +61,11 @@ class DiviComposition
|
|||||||
return $bound;
|
return $bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The one checker of $variable(…)$ values of this composition, with the entry's live map (S22, S31). */
|
/**
|
||||||
|
* The one checker of $variable(…)$ values of this composition, with the entry's live map (S22, S31).
|
||||||
|
*
|
||||||
|
* @internal Public for tests; code uses cleaner() / composer().
|
||||||
|
*/
|
||||||
public function references(): VariableRef
|
public function references(): VariableRef
|
||||||
{
|
{
|
||||||
return $this->references ??= new VariableRef(
|
return $this->references ??= new VariableRef(
|
||||||
@@ -70,7 +74,11 @@ class DiviComposition
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The one Placeholders instance of this composition (ruling S31). */
|
/**
|
||||||
|
* The one Placeholders instance of this composition (ruling S31).
|
||||||
|
*
|
||||||
|
* @internal Public for tests; code uses attrWriter() / composer().
|
||||||
|
*/
|
||||||
public function placeholders(): Placeholders
|
public function placeholders(): Placeholders
|
||||||
{
|
{
|
||||||
return $this->placeholders ??= new Placeholders($this->design->read());
|
return $this->placeholders ??= new Placeholders($this->design->read());
|
||||||
@@ -100,6 +108,7 @@ class DiviComposition
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @internal Public for tests; code uses composer() / editor(). */
|
||||||
public function rules(): StructureRules
|
public function rules(): StructureRules
|
||||||
{
|
{
|
||||||
return new StructureRules($this->modules->catalog());
|
return new StructureRules($this->modules->catalog());
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ final class Limits
|
|||||||
return $this->all()['log_retention_days'];
|
return $this->all()['log_retention_days'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Reserved for design-system snapshots (Etappe 3); LimitsTab keeps the field hidden until then. */
|
||||||
public function snapshotCount(): int
|
public function snapshotCount(): int
|
||||||
{
|
{
|
||||||
return $this->all()['snapshot_count'];
|
return $this->all()['snapshot_count'];
|
||||||
|
|||||||
@@ -442,9 +442,10 @@ final class ComposerTest extends TestCase
|
|||||||
public function testAutoLabel(): void
|
public function testAutoLabel(): void
|
||||||
{
|
{
|
||||||
$composer = ComposeFixture::composer();
|
$composer = ComposeFixture::composer();
|
||||||
|
$label = static fn (array $result): mixed => $result['blocks'][0]->attrs()['module']['meta']['adminLabel']['desktop']['value'] ?? null;
|
||||||
|
|
||||||
self::assertSame('Hero – Button', $composer->autoLabel('divi/button', 'Hero'));
|
self::assertSame('Hero – Button', $label($composer->compose([['type' => 'button', 'text' => 'Los']], Block::create('divi/column'), 'n', 'Hero')));
|
||||||
self::assertSame('Button', $composer->autoLabel('divi/button', ''));
|
self::assertSame('Button', $label($composer->compose([['type' => 'button', 'text' => 'Los']], Block::create('divi/column'), 'n', '')));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testComposesIntoAnExistingParent(): void
|
public function testComposesIntoAnExistingParent(): void
|
||||||
|
|||||||
Reference in New Issue
Block a user