Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 70d25af

Browse files
committed
fix santizer config
1 parent f23aaa8 commit 70d25af

File tree

15 files changed

+37
-30
lines changed

15 files changed

+37
-30
lines changed

src/BlockFactory.php

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
public static function parse(string $data, ?array $tools = null, array $allowedTags = []): array
4343
{
4444
try {
45+
/** @var array{time: int, blocks: array<array{id: string, type: string, data: mixed}>} $blocks */
4546
$blocks = json_decode($data, true, flags: JSON_THROW_ON_ERROR);
4647
$mapper = fn (array $block): Block => self::create($block, self::getAllowedTags($block, $allowedTags));
4748

@@ -56,10 +57,10 @@ public static function parse(string $data, ?array $tools = null, array $allowedT
5657
}
5758
}
5859

59-
private static function filter(array $data, array $tools): array
60-
{
61-
return array_filter($data, fn (array $block): bool => isset($tools[$block['type']]));
62-
}
60+
// private static function filter(array $data, array $tools): array
61+
// {
62+
// return array_filter($data, fn (array $block): bool => isset($tools[$block['type']]));
63+
// }
6364

6465
/**
6566
* @throws EditorException
@@ -83,25 +84,29 @@ private static function create(array $data, array $allowedTags = []): Block
8384
'raw' => Raw::create($data, $allowedTags),
8485
'table' => Table::create($data, $allowedTags),
8586
'warning' => Warning::create($data, $allowedTags),
87+
default => throw new EditorException(sprintf('Block type %s not supported', $data['type'])),
8688
};
8789
} catch (\Throwable $e) {
8890
throw new EditorException($e->getMessage(), previous: $e);
8991
}
9092
}
9193

92-
private static function getAllowedTags(mixed $block, array $allowedTags): array
94+
private static function getAllowedTags(array $block, array $allowedTags): array
9395
{
9496
Assert::keyExists($block, 'type');
9597

9698
return $allowedTags[$block['type']] ?? [];
9799
}
98100

99-
private static function getSchema(string $schema): array
100-
{
101-
$filename = sprintf('%s/schemas/%s.schema.json', dirname(__DIR__), $schema);
102-
$content = file_get_contents($filename);
103-
Assert::string($content, sprintf('Schema for block type %s not found', $schema));
104-
105-
return json_decode($content, true);
106-
}
101+
// private static function getSchema(string $schema): array
102+
// {
103+
// $filename = sprintf('%s/schemas/%s.schema.json', dirname(__DIR__), $schema);
104+
// $content = file_get_contents($filename);
105+
// Assert::string($content, sprintf('Schema for block type %s not found', $schema));
106+
//
107+
// /** @var array $schema */
108+
// $schema = json_decode($content, true);
109+
//
110+
// return $schema;
111+
// }
107112
}

src/Blocks/Attaches.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
final readonly class Attaches extends Block
2929
{
30-
public function __construct(string $id, string $type, array $data, ?array $tunes, ?array $allowedTags = null)
30+
public function __construct(string $id, string $type, array $data, ?array $tunes = [], ?array $allowedTags = null)
3131
{
3232
Assert::eq($type, 'attaches');
3333
Assert::keyExists($data, 'file');

src/Blocks/Block.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
/**
2020
* Class Block.
2121
*
22+
* @phpstan-consistent-constructor
23+
*
2224
* @author bernard-ng <bernard@devscast.tech>
2325
*/
2426
abstract readonly class Block
@@ -48,7 +50,7 @@ public static function create(array $data, array $allowedTags = []): static
4850

4951
public function sanitize(): string
5052
{
51-
$sanitizer = Sanitizer::create($this->allowedTags);
53+
$sanitizer = Sanitizer::create($this->allowedTags ?? []);
5254

5355
return $sanitizer->sanitize($this->toHtml());
5456
}

src/Blocks/Code.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
final readonly class Code extends Block
2929
{
30-
public function __construct(string $id, string $type, array $data, ?array $tunes, ?array $allowedTags = null)
30+
public function __construct(string $id, string $type, array $data, ?array $tunes = [], ?array $allowedTags = null)
3131
{
3232
Assert::eq($type, 'code');
3333
Assert::keyExists($data, 'code');

src/Blocks/Delimiter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
final readonly class Delimiter extends Block
2929
{
30-
public function __construct(string $id, string $type, array $data, ?array $tunes, ?array $allowedTags = null)
30+
public function __construct(string $id, string $type, array $data, ?array $tunes = [], ?array $allowedTags = null)
3131
{
3232
Assert::eq($type, 'delimiter');
3333

src/Blocks/Embed.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
final readonly class Embed extends Block
2929
{
30-
public function __construct(string $id, string $type, array $data, ?array $tunes, ?array $allowedTags = null)
30+
public function __construct(string $id, string $type, array $data, ?array $tunes = [], ?array $allowedTags = null)
3131
{
3232
Assert::eq($type, 'embed');
3333
Assert::keyExists($data, 'service');

src/Blocks/Header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
final readonly class Header extends Block
2929
{
30-
public function __construct(string $id, string $type, array $data, ?array $tunes, ?array $allowedTags = null)
30+
public function __construct(string $id, string $type, array $data, ?array $tunes = [], ?array $allowedTags = null)
3131
{
3232
Assert::eq($type, 'header');
3333
Assert::keyExists($data, 'text');

src/Blocks/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*/
2828
final readonly class Image extends Block
2929
{
30-
public function __construct(string $id, string $type, array $data, ?array $tunes, ?array $allowedTags = null)
30+
public function __construct(string $id, string $type, array $data, ?array $tunes = [], ?array $allowedTags = null)
3131
{
3232
Assert::eq($type, 'image');
3333
Assert::keyExists($data, 'file');

src/Blocks/Listing.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
*/
2929
final readonly class Listing extends Block
3030
{
31-
public function __construct(string $id, string $type, array $data, ?array $tunes, ?array $allowedTags = null)
31+
public function __construct(string $id, string $type, array $data, ?array $tunes = [], ?array $allowedTags = null)
3232
{
3333
Assert::eq($type, 'list');
3434
Assert::keyExists($data, 'items');

src/Blocks/Paragraph.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
*/
3030
final readonly class Paragraph extends Block
3131
{
32-
public function __construct(string $id, string $type, array $data, ?array $tunes, ?array $allowedTags = null)
32+
public function __construct(string $id, string $type, array $data, ?array $tunes = [], ?array $allowedTags = null)
3333
{
3434
Assert::eq($type, 'paragraph');
3535
Assert::keyExists($data, 'text');
@@ -45,8 +45,8 @@ public function __construct(string $id, string $type, array $data, ?array $tunes
4545
#[\Override]
4646
public function toHtml(): string
4747
{
48-
return <<<HTML
48+
return trim(<<<HTML
4949
<p id="{$this->id}">{$this->data['text']}</p>
50-
HTML;
50+
HTML);
5151
}
5252
}

0 commit comments

Comments
 (0)