6
6
use CodexSoft \JsonApi \Form \Type \BooleanType \BooleanType ;
7
7
use CodexSoft \JsonApi \Form \Type \JsonType \JsonType ;
8
8
use CodexSoft \JsonApi \Form \Type \MixedType \MixedType ;
9
+ use CodexSoft \JsonApi \Helper \Minifaker ;
9
10
use CodexSoft \JsonApi \Response \ResponseWrappedDataInterface ;
10
11
use Psr \Log \LoggerInterface ;
11
12
use Psr \Log \NullLogger ;
@@ -20,13 +21,13 @@ class SymfonyFormExampleGenerator
20
21
private bool $ preferDefaultValue = false ;
21
22
22
23
private FormFactoryInterface $ formFactory ;
23
- private \Faker \Factory $ faker ;
24
+ // private \Faker\Factory $faker;
24
25
private LoggerInterface $ logger ;
25
26
private bool $ skipNotReqiredElements = false ;
26
27
27
28
public function __construct ()
28
29
{
29
- $ this ->faker = \Faker \Factory::create ( 'ru_RU ' );
30
+ // $this->faker = \Faker\Factory::create( 'ru_RU' );
30
31
$ this ->logger = new NullLogger ;
31
32
$ this ->formFactory = self ::generateFormFactory ();
32
33
}
@@ -268,31 +269,31 @@ protected function generateScalarExample(AbstractType $innerType, array $constra
268
269
}
269
270
270
271
if ($ innerType instanceof Type \IntegerType) {
271
- return $ this -> faker -> numberBetween ($ min ,$ max );
272
+ return Minifaker:: numberBetween ($ min ,$ max );
272
273
}
273
274
274
275
if ($ innerType instanceof Type \NumberType) {
275
- return $ this -> faker -> randomFloat (6 ,$ min ,$ max );
276
+ return Minifaker:: randomFloat (6 ,$ min ,$ max );
276
277
}
277
278
278
279
if ($ innerType instanceof Type \PercentType) {
279
- return $ this -> faker -> randomFloat (null ,0 ,1 );
280
+ return Minifaker:: randomFloat (null ,0 ,1 );
280
281
}
281
282
282
283
if ($ innerType instanceof Type \TextType || $ innerType instanceof Type \TextareaType) {
283
284
if ($ minLength === 0 ) {
284
- return $ this -> faker -> realText ( $ maxLength );
285
+ return Minifaker:: lexify ( );
285
286
}
286
287
// todo: as faker has not minLength parameter from text out of the box, currently using password...
287
- return $ this -> faker -> password ( $ minLength , $ maxLength );
288
+ return Minifaker:: lexify ( \str_repeat ( ' ? ' , $ maxLength) );
288
289
}
289
290
290
291
if ($ innerType instanceof Type \EmailType) {
291
- return $ this -> faker -> email ;
292
+ return Minifaker:: lexify (). ' @example.com ' ;
292
293
}
293
294
294
295
if ($ innerType instanceof Type \UrlType) {
295
- return $ this -> faker -> url ;
296
+ return Minifaker:: lexify (). ' .com ' ;
296
297
}
297
298
298
299
if ($ innerType instanceof BooleanType) {
@@ -305,20 +306,23 @@ protected function generateScalarExample(AbstractType $innerType, array $constra
305
306
}
306
307
307
308
if ($ innerType instanceof Type \CheckboxType) {
308
- return $ this ->faker ->boolean ;
309
+ return true ;
310
+ //return Minifaker::boolean;
309
311
}
310
312
311
313
if ($ innerType instanceof Type \DateType) {
312
- return $ this ->faker ->date (DateAndTime::FORMAT_YMD );
314
+ return '2020-10-20 ' ;
315
+ //return Minifaker::date(DateAndTime::FORMAT_YMD);
313
316
}
314
317
315
318
if ($ innerType instanceof Type \TimeType) {
316
- return $ this ->faker ->time (DateAndTime::FORMAT_HOURMIN );
319
+ return '02:42 ' ;
320
+ //return Minifaker::time(DateAndTime::FORMAT_HOURMIN);
317
321
}
318
322
319
323
if ($ innerType instanceof Type \DateTimeType) {
320
324
// todo: timestamp?
321
- return $ this -> faker -> dateTime ->format (DateAndTime::FORMAT_YMD_HIS );
325
+ return ( new \ DateTime ()) ->format (DateAndTime::FORMAT_YMD_HIS );
322
326
//return 'DateTimeType not implemented';
323
327
}
324
328
0 commit comments