refactor: ValueKind enum instead of kind string literals (L1)

enum ValueKind: string { Html, Code, Url, Text } with strictness() and
tightens(self $routed) (the S33a rule formerly AttrWriter/ValueCleaner::tightens
over STRICTNESS). ValueCleaner::clean() takes ?ValueKind, kindOf()/kind()/
unknownKind() return it, the sanitizer match is exhaustive over the four cases;
the "Feldart" message prints ->value, so its text is unchanged. ShortformWriter
drops the identity map CLEAN_KIND for ValueKind::tryFrom($spec['kind']) ??
ValueKind::Text; Composer and ShortformWriter pass ValueKind::Text/Url.
The installed PHPCompatibility sniffs do not know enums: two sniffs are disabled
in ValueKind.php only, with the reason.
Tests: ValueCleanerTest passes/asserts ValueKind cases instead of strings;
+ValueKindTest (full tightens matrix, case values).

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:
2026-09-26 18:13:23 +02:00
co-authored by Claude Opus 5.5
parent 62ce99e558
commit 570c1e6142
6 changed files with 143 additions and 81 deletions
@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Compose;
use LIT\MCP\Integrations\Divi\Compose\ValueKind;
use PHPUnit\Framework\TestCase;
/** Ruling S33a: an override may only tighten – code < html < text; url only to url. */
final class ValueKindTest extends TestCase
{
public function testTightensMatrix(): void
{
$allowed = [
'code' => ['code'],
'html' => ['code', 'html'],
'text' => ['code', 'html', 'text'],
'url' => ['url'],
];
foreach (ValueKind::cases() as $override) {
foreach (ValueKind::cases() as $routed) {
self::assertSame(
in_array($routed->value, $allowed[$override->value], true),
$override->tightens($routed),
$override->value . ' over ' . $routed->value
);
}
}
}
public function testValuesAreTheCuratedKindNames(): void
{
self::assertSame(['html', 'code', 'url', 'text'], array_map(static fn (ValueKind $kind): string => $kind->value, ValueKind::cases()));
self::assertNull(ValueKind::tryFrom('richtext'));
}
}