Skip to content

Commit 5c48250

Browse files
committed
refactor: cleanup
1 parent 27ecb82 commit 5c48250

9 files changed

Lines changed: 1 addition & 33 deletions

File tree

packages/core/src/Data/BlockBuilder.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,15 @@ class BlockBuilder extends PresetChild
1818
*/
1919
public static function forTemplate(string $id, string $type): static
2020
{
21-
// If type is a BlockInterface class, resolve to type string
2221
if (class_exists($type) && is_subclass_of($type, BlockInterface::class)) {
2322
$type = $type::type();
2423
}
2524

26-
// If type is a BlockPreset class, convert to PresetChild
2725
if (class_exists($type) && is_subclass_of($type, BlockPreset::class)) {
2826
/** @var BlockPreset $type */
2927
return static::fromPresetChild($type::asChild(), $id);
3028
}
3129

32-
// Create new instance with type
3330
$instance = new static($type);
3431
$instance->id = $id;
3532

@@ -44,7 +41,6 @@ public static function fromPresetChild(PresetChild $child, string $id): static
4441
{
4542
$instance = new static($child->type);
4643

47-
// Copy all properties from PresetChild
4844
$instance->id = $id;
4945
$instance->name = $child->name;
5046
$instance->properties = $child->properties;

packages/core/src/Data/BlockPreset.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ protected function getName(): string
5353
{
5454
$class = (new \ReflectionClass(static::class))->getShortName();
5555

56-
// Remove "Preset" suffix if present
5756
$class = preg_replace('/Preset$/', '', $class);
5857

59-
// Convert PascalCase to spaces (e.g., "RichText" -> "Rich Text")
6058
$words = preg_replace('/(?<!^)[A-Z]/', ' $0', $class);
6159

6260
return trim($words);

packages/core/src/Data/PresetChild.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,8 @@ protected function getType(): string
5858
{
5959
$class = (new \ReflectionClass(static::class))->getShortName();
6060

61-
// Remove "PresetChild" or "Child" suffix if present
6261
$class = preg_replace('/(PresetChild|Child)$/', '', $class);
6362

64-
// Convert PascalCase to kebab-case (e.g., "Paragraph" -> "paragraph")
6563
$kebab = strtolower(preg_replace('/(?<!^)[A-Z]/', '-$0', $class));
6664

6765
return $kebab;
@@ -71,10 +69,7 @@ protected function getType(): string
7169
* Build the preset child configuration.
7270
* Override this method in subclasses to define structure.
7371
*/
74-
protected function build(): void
75-
{
76-
// Base implementation does nothing
77-
}
72+
protected function build(): void {}
7873

7974
/**
8075
* Set the block type.

packages/core/src/Data/Template.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,12 @@ public static function make(): static
3434
*/
3535
public function block(string $id, string $type, ?callable $config = null): static
3636
{
37-
// Create new block using factory
3837
$block = BlockBuilder::forTemplate($id, $type);
3938

40-
// Apply configuration callback if provided
4139
if ($config !== null) {
4240
$config($block);
4341
}
4442

45-
// Add block to template
4643
$this->blocks[] = $block;
4744

4845
return $this;

packages/core/src/Services/BlockFlattener.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ protected function extractBlockRecursively(array $blockData, array &$flatBlocks,
8888

8989
$flatBlock['children'] = $uniqueChildIds;
9090
} elseif (! empty($children) && is_array($children)) {
91-
// These are just ID references, keep as-is
9291
$flatBlock['children'] = $children;
9392
}
9493

@@ -170,13 +169,8 @@ protected function extractChildBlocks($children): array
170169
*/
171170
protected function sanitizeTypeForId(string $type): string
172171
{
173-
// Remove @ prefix
174172
$sanitized = ltrim($type, '@');
175-
176-
// Replace / and - with _
177173
$sanitized = str_replace(['/', '-'], '_', $sanitized);
178-
179-
// Convert to snake_case
180174
$sanitized = strtolower($sanitized);
181175

182176
return $sanitized ?: 'block';

packages/laravel/src/BlockDatastore.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ public function loadFile(string $sourceFilePath): void
2828

2929
$blocks = $this->getBlocksArray($sourceFilePath);
3030

31-
// Create BlockData for each block and store in cache
3231
foreach ($blocks as $blockId => $blockData) {
3332
$block = Craftile::createBlockData(
3433
$blockData,
@@ -124,7 +123,6 @@ public function getBlocksArray(string $sourceFilePath): array
124123
*/
125124
protected function assignBlockIndices(array &$blocks, array $template): void
126125
{
127-
// Assign indices for blocks in regions
128126
foreach ($template['regions'] ?? [] as $region) {
129127
foreach ($region['blocks'] ?? [] as $index => $blockId) {
130128
if (isset($blocks[$blockId])) {
@@ -133,7 +131,6 @@ protected function assignBlockIndices(array &$blocks, array $template): void
133131
}
134132
}
135133

136-
// Assign indices for child blocks
137134
foreach ($blocks as $blockId => $blockData) {
138135
foreach ($blockData['children'] ?? [] as $index => $childId) {
139136
if (isset($blocks[$childId])) {

packages/laravel/src/Support/HandleUpdates.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ public function __construct(
2121
*/
2222
public function execute(string $sourceFilePath, UpdateRequest $updateRequest, ?array $targetRegions = null): array
2323
{
24-
// Get fully normalized data from parser's pipeline
2524
$sourceData = $this->parser->parse($sourceFilePath);
2625

2726
if (! $this->hasUpdates($sourceData, $updateRequest, $targetRegions)) {
@@ -45,13 +44,10 @@ private function applyUpdates(array $data, UpdateRequest $updateRequest, ?array
4544

4645
foreach ($blocksToRemove as $blockId) {
4746
if (isset($data['blocks'][$blockId])) {
48-
// Get all descendants to remove entire subtree
4947
$descendants = $this->getAllDescendants($blockId, $data['blocks']);
5048

51-
// Remove the block itself
5249
unset($data['blocks'][$blockId]);
5350

54-
// Remove all descendants
5551
foreach ($descendants as $descendantId) {
5652
if (isset($data['blocks'][$descendantId])) {
5753
unset($data['blocks'][$descendantId]);

packages/laravel/src/View/WrapperCompiler.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ class WrapperCompiler
2323
*/
2424
public static function compileWrapper(string $emmet, string $blockId): array
2525
{
26-
// If emmet doesn't contain __content__, append it
2726
if (! str_contains($emmet, '__content__')) {
2827
$emmet .= '{__content__}';
2928
}
3029

31-
// Parse the emmet syntax to HTML
3230
$html = SimpleEmmetParser::parse($emmet);
3331

3432
// Inject data-block attribute into the first tag
@@ -39,7 +37,6 @@ public static function compileWrapper(string $emmet, string $blockId): array
3937
1
4038
);
4139

42-
// Split by __content__ placeholder
4340
[$opening, $closing] = explode('__content__', $html, 2);
4441

4542
return [$opening, $closing];

tests/core/Services/BlockFlattenerTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,11 @@
6464
$blocks = $result['blocks'];
6565
expect($blocks)->toHaveCount(3); // parent + 2 children
6666

67-
// Check parent block
6867
expect($blocks['parent'])->toHaveKey('id', 'parent');
6968
expect($blocks['parent'])->toHaveKey('type', 'container');
7069
expect($blocks['parent'])->toHaveKey('children');
7170
expect($blocks['parent']['children'])->toHaveCount(2);
7271

73-
// Check children exist
7472
$childIds = $blocks['parent']['children'];
7573
expect($blocks)->toHaveKey($childIds[0]);
7674
expect($blocks)->toHaveKey($childIds[1]);

0 commit comments

Comments
 (0)