Skip to content

Commit

Permalink
Remove unnecessary class property from faker converter
Browse files Browse the repository at this point in the history
  • Loading branch information
guvra committed Feb 20, 2024
1 parent 3700467 commit 13c61db
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/Converter/Proxy/Faker.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

namespace Smile\GdprDump\Converter\Proxy;

use Faker\Generator;
use Smile\GdprDump\Converter\ConverterInterface;
use Smile\GdprDump\Converter\Parameters\Parameter;
use Smile\GdprDump\Converter\Parameters\ParameterProcessor;
use Smile\GdprDump\Faker\FakerService;

class Faker implements ConverterInterface
{
private Generator $faker;
private object $provider;
private string $method;
private array $arguments;
Expand All @@ -22,9 +20,8 @@ class Faker implements ConverterInterface
*/
private array $placeholders = [];

public function __construct(FakerService $faker)
public function __construct(private FakerService $fakerService)
{
$this->faker = $faker->getGenerator();
}

/**
Expand All @@ -37,19 +34,20 @@ public function setParameters(array $parameters): void
->addParameter('arguments', Parameter::TYPE_ARRAY, false, [])
->process($parameters);

// Create the formatter now to ensure that errors related to undefined formatters
// are triggered before the start of the dump process
$formatter = $input->get('formatter');
$this->arguments = $input->get('arguments') ?? [];
// @phpstan-ignore-next-line getFormatter function always returns an array with 2 items
[$this->provider, $this->method] = $this->fakerService
->getGenerator()
->getFormatter($formatter);

$this->arguments = $input->get('arguments') ?? [];
foreach ($this->arguments as $name => $value) {
if ($value === '{{value}}') {
$this->placeholders[] = $name;
}
}

// Faster than calling the "format" method of the Faker generator
// (the "format" method uses call_user_func_array, which is very slow)
// @phpstan-ignore-next-line getFormatter function always returns an array with 2 items
[$this->provider, $this->method] = $this->faker->getFormatter($formatter);
}

/**
Expand Down

0 comments on commit 13c61db

Please sign in to comment.