Skip to content

Commit ef7681f

Browse files
committed
Fakeable contract.
1 parent 17023d0 commit ef7681f

17 files changed

+57
-20
lines changed

src/Blocks/Attaches.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class Attaches extends Block
11+
class Attaches extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Blocks/Checklist.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class Checklist extends Block
11+
class Checklist extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Blocks/Code.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class Code extends Block
11+
class Code extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Blocks/Delimiter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class Delimiter extends Block
11+
class Delimiter extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Blocks/Embed.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class Embed extends Block
11+
class Embed extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Blocks/Header.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class Header extends Block
11+
class Header extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Blocks/Image.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class Image extends Block
11+
class Image extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Blocks/LinkTool.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class LinkTool extends Block
11+
class LinkTool extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Blocks/ListBlock.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910
use Illuminate\Validation\Rule;
1011

11-
class ListBlock extends Block
12+
class ListBlock extends Block implements Fakeable
1213
{
1314
/**
1415
* Tag allow list for purifying data.

src/Blocks/Paragraph.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class Paragraph extends Block
11+
class Paragraph extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Blocks/Personality.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class Personality extends Block
11+
class Personality extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Blocks/Quote.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910
use Illuminate\Validation\Rule;
1011

11-
class Quote extends Block
12+
class Quote extends Block implements Fakeable
1213
{
1314
/**
1415
* Tag allow list for purifying data.

src/Blocks/Raw.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67

7-
class Raw extends Block
8+
class Raw extends Block implements Fakeable
89
{
910
/**
1011
* Tag allow list for purifying data.

src/Blocks/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6-
use BumpCore\EditorPhp\Block\Data;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
77
use BumpCore\EditorPhp\EditorPhp;
88
use BumpCore\EditorPhp\Helpers;
99
use Illuminate\Support\Facades\View;
1010

11-
class Table extends Block
11+
class Table extends Block implements Fakeable
1212
{
1313
/**
1414
* Tag allow list for purifying data.

src/Blocks/Warning.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
namespace BumpCore\EditorPhp\Blocks;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use BumpCore\EditorPhp\EditorPhp;
78
use BumpCore\EditorPhp\Helpers;
89
use Illuminate\Support\Facades\View;
910

10-
class Warning extends Block
11+
class Warning extends Block implements Fakeable
1112
{
1213
/**
1314
* Tag allow list for purifying data.

src/Contracts/Fakeable.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace BumpCore\EditorPhp\Contracts;
4+
5+
use Faker\Generator;
6+
7+
interface Fakeable
8+
{
9+
/**
10+
* Generates fake data for the block.
11+
*
12+
* @param Generator $generator
13+
*
14+
* @return mixed
15+
*/
16+
public static function fake(Generator $generator): mixed;
17+
}

src/EditorPhp.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace BumpCore\EditorPhp;
44

55
use BumpCore\EditorPhp\Block\Block;
6+
use BumpCore\EditorPhp\Contracts\Fakeable;
67
use Carbon\Carbon;
78
use Illuminate\Contracts\Support\Arrayable;
89
use Illuminate\Contracts\Support\Htmlable;
@@ -223,20 +224,25 @@ public function __toString(): string
223224
*/
224225
public static function fake(bool $instance = false, int $minLength = 8, int $maxLength = 30): EditorPhp|string
225226
{
227+
if (!class_exists(\Faker\Factory::class, false))
228+
{
229+
throw new \Exception('Please install `fakerphp/faker` package in order to generate fake data.');
230+
}
231+
226232
$faker = \Faker\Factory::create();
227-
$blocks = array_filter(Parser::$blocks, fn (string $provider) => method_exists($provider, 'fake'));
233+
$blocks = array_filter(Parser::$blocks, fn (string $provider) => is_subclass_of($provider, Fakeable::class));
228234
$generatedBlocks = [];
229235

230-
foreach (range(0, fake()->numberBetween($minLength, $maxLength)) as $index)
236+
foreach (range(0, $faker->numberBetween($minLength, $maxLength)) as $index)
231237
{
232-
$block = fake()->randomElement($blocks);
238+
$block = $faker->randomElement($blocks);
233239
$generatedBlocks[] = (new ($block)($block::fake($faker)))->toArray();
234240
}
235241

236242
$generated = json_encode([
237243
'time' => (int) Carbon::now()->getPreciseTimestamp(3),
238244
'blocks' => $generatedBlocks,
239-
'version' => fake()->semver(),
245+
'version' => $faker->semver(),
240246
]);
241247

242248
return $instance ? static::make($generated) : $generated;

0 commit comments

Comments
 (0)