Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
DatabaseText | |
100.00% |
9 / 9 |
|
100.00% |
4 / 4 |
4 | |
100.00% |
1 / 1 |
getRegularExpression | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
convert | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createRandom | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createSchema | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Apie\Core\ValueObjects; |
3 | |
4 | use Apie\Core\Attributes\Description; |
5 | use Apie\Core\Attributes\FakeMethod; |
6 | use Apie\Core\Attributes\ProvideIndex; |
7 | use Apie\Core\Attributes\SchemaMethod; |
8 | use Apie\Core\ValueObjects\Concerns\IndexesWords; |
9 | use Apie\Core\ValueObjects\Interfaces\HasRegexValueObjectInterface; |
10 | use Faker\Generator; |
11 | |
12 | #[FakeMethod('createRandom')] |
13 | #[SchemaMethod('createSchema')] |
14 | #[ProvideIndex('getIndexes')] |
15 | #[Description('Any text with a maximum length of 65535 characters that fit in a TEXT field in a database')] |
16 | final class DatabaseText implements HasRegexValueObjectInterface |
17 | { |
18 | use IndexesWords; |
19 | use IsStringWithRegexValueObject; |
20 | |
21 | public static function getRegularExpression(): string |
22 | { |
23 | return '/^.{0,65535}$/s'; |
24 | } |
25 | |
26 | protected function convert(string $input): string |
27 | { |
28 | return trim($input); |
29 | } |
30 | |
31 | public static function createRandom(Generator $generator): self |
32 | { |
33 | return new DatabaseText($generator->realText(1024)); |
34 | } |
35 | |
36 | /** |
37 | * Provide OpenAPI schema. This is overwritten as some libraries will try to generate strings of 65535 characters |
38 | * all the time for example strings resulting in terrible performance. |
39 | * |
40 | * @return array<string, string|int> |
41 | */ |
42 | public static function createSchema(): array |
43 | { |
44 | return [ |
45 | 'type' => 'string', |
46 | 'minLength' => 0, |
47 | 'maxLength' => 65535, |
48 | 'example' => 'Lorem Ipsum', |
49 | ]; |
50 | } |
51 | } |