Skip to content

Commit 24f4338

Browse files
committed
remove faker dependency
1 parent 811c880 commit 24f4338

File tree

3 files changed

+458
-14
lines changed

3 files changed

+458
-14
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"require": {
88
"php": "^7.4|^8",
99
"ext-json": "*",
10-
"fzaninotto/faker": "^1.7",
1110
"symfony/form": "^4.0 || ^5.0",
1211
"symfony/console": "^4.1 || ^5.0",
1312
"symfony/framework-bundle": "^4.3 || ^5.0",

src/CodexSoft/JsonApi/Form/SymfonyFormExampleGenerator.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use CodexSoft\JsonApi\Form\Type\BooleanType\BooleanType;
77
use CodexSoft\JsonApi\Form\Type\JsonType\JsonType;
88
use CodexSoft\JsonApi\Form\Type\MixedType\MixedType;
9+
use CodexSoft\JsonApi\Helper\Minifaker;
910
use CodexSoft\JsonApi\Response\ResponseWrappedDataInterface;
1011
use Psr\Log\LoggerInterface;
1112
use Psr\Log\NullLogger;
@@ -20,13 +21,13 @@ class SymfonyFormExampleGenerator
2021
private bool $preferDefaultValue = false;
2122

2223
private FormFactoryInterface $formFactory;
23-
private \Faker\Factory $faker;
24+
//private \Faker\Factory $faker;
2425
private LoggerInterface $logger;
2526
private bool $skipNotReqiredElements = false;
2627

2728
public function __construct()
2829
{
29-
$this->faker = \Faker\Factory::create( 'ru_RU' );
30+
//$this->faker = \Faker\Factory::create( 'ru_RU' );
3031
$this->logger = new NullLogger;
3132
$this->formFactory = self::generateFormFactory();
3233
}
@@ -268,31 +269,31 @@ protected function generateScalarExample(AbstractType $innerType, array $constra
268269
}
269270

270271
if ($innerType instanceof Type\IntegerType) {
271-
return $this->faker->numberBetween($min,$max);
272+
return Minifaker::numberBetween($min,$max);
272273
}
273274

274275
if ($innerType instanceof Type\NumberType) {
275-
return $this->faker->randomFloat(6,$min,$max);
276+
return Minifaker::randomFloat(6,$min,$max);
276277
}
277278

278279
if ($innerType instanceof Type\PercentType) {
279-
return $this->faker->randomFloat(null,0,1);
280+
return Minifaker::randomFloat(null,0,1);
280281
}
281282

282283
if ($innerType instanceof Type\TextType || $innerType instanceof Type\TextareaType) {
283284
if ($minLength === 0) {
284-
return $this->faker->realText($maxLength);
285+
return Minifaker::lexify();
285286
}
286287
// 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));
288289
}
289290

290291
if ($innerType instanceof Type\EmailType) {
291-
return $this->faker->email;
292+
return Minifaker::lexify().'@example.com';
292293
}
293294

294295
if ($innerType instanceof Type\UrlType) {
295-
return $this->faker->url;
296+
return Minifaker::lexify().'.com';
296297
}
297298

298299
if ($innerType instanceof BooleanType) {
@@ -305,20 +306,23 @@ protected function generateScalarExample(AbstractType $innerType, array $constra
305306
}
306307

307308
if ($innerType instanceof Type\CheckboxType) {
308-
return $this->faker->boolean;
309+
return true;
310+
//return Minifaker::boolean;
309311
}
310312

311313
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);
313316
}
314317

315318
if ($innerType instanceof Type\TimeType) {
316-
return $this->faker->time(DateAndTime::FORMAT_HOURMIN);
319+
return '02:42';
320+
//return Minifaker::time(DateAndTime::FORMAT_HOURMIN);
317321
}
318322

319323
if ($innerType instanceof Type\DateTimeType) {
320324
// todo: timestamp?
321-
return $this->faker->dateTime->format(DateAndTime::FORMAT_YMD_HIS);
325+
return (new \DateTime())->format(DateAndTime::FORMAT_YMD_HIS);
322326
//return 'DateTimeType not implemented';
323327
}
324328

0 commit comments

Comments
 (0)