1313use WebProject \PhpOpenApiMockServer \Middleware \MockMiddleware \Faker \Options ;
1414
1515/** @internal */
16- final class StringFaker implements FakerInterface
16+ final readonly class StringFaker implements FakerInterface
1717{
18- private Generator $ faker ;
18+ private Generator $ generator ;
1919
2020 public function __construct ()
2121 {
22- $ this ->faker = Factory::create ();
22+ $ this ->generator = Factory::create ();
2323 }
2424
2525 public function generate (Schema $ schema , Options $ options , FakerRegistry $ fakerRegistry , FakerContext $ fakerContext ): ?string
@@ -35,27 +35,27 @@ private function generateDynamic(Schema $schema): string
3535 {
3636 if (!empty ($ schema ->enum )) {
3737 /** @var string $value */
38- $ value = $ this ->faker ->randomElement ($ schema ->enum );
38+ $ value = $ this ->generator ->randomElement ($ schema ->enum );
3939
4040 return $ value ;
4141 }
4242
4343 if (null !== $ schema ->pattern ) {
44- return $ this ->faker ->regexify ($ schema ->pattern );
44+ return $ this ->generator ->regexify ($ schema ->pattern );
4545 }
4646
4747 $ maxLength = $ schema ->maxLength ?? 255 ;
4848
4949 return match ($ schema ->format ) {
50- 'date ' => $ this ->faker ->date (),
51- 'date-time ' => $ this ->faker ->iso8601 (),
52- 'email ' => $ this ->faker ->email (),
53- 'uuid ' => $ this ->faker ->uuid (),
54- 'uri ' => $ this ->faker ->url (),
55- 'hostname ' => $ this ->faker ->domainName (),
56- 'ipv4 ' => $ this ->faker ->ipv4 (),
57- 'ipv6 ' => $ this ->faker ->ipv6 (),
58- default => $ this ->faker ->text ($ maxLength > 5 ? $ maxLength : 20 ),
50+ 'date ' => $ this ->generator ->date (),
51+ 'date-time ' => $ this ->generator ->iso8601 (),
52+ 'email ' => $ this ->generator ->email (),
53+ 'uuid ' => $ this ->generator ->uuid (),
54+ 'uri ' => $ this ->generator ->url (),
55+ 'hostname ' => $ this ->generator ->domainName (),
56+ 'ipv4 ' => $ this ->generator ->ipv4 (),
57+ 'ipv6 ' => $ this ->generator ->ipv6 (),
58+ default => $ this ->generator ->text ($ maxLength > 5 ? $ maxLength : 20 ),
5959 };
6060 }
6161
0 commit comments