Skip to content

Commit

Permalink
Fix setGenerator (#4)
Browse files Browse the repository at this point in the history
* Fix setGenerator

* Fix setGenerator -> option 2, even better imo

* Fix setGenerator -> addition to option2, keeping the option to set the generator on init funtional
  • Loading branch information
Pwelling authored and arrilot committed Feb 28, 2017
1 parent 166115a commit 49e7143
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/Anonymizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ class Anonymizer
public function __construct(DatabaseInterface $database, $generator = null)
{
$this->database = $database;

$this->setGenerator($generator);
if (!is_null($generator)) {
$this->setGenerator($generator);
}
}

/**
Expand All @@ -51,14 +52,7 @@ public function __construct(DatabaseInterface $database, $generator = null)
*/
public function setGenerator($generator)
{
if ($generator !== null) {
$this->generator = $generator;
}

if (class_exists('\Faker\Factory')) {
$this->generator = Factory::create();
}

$this->generator = $generator;
return $this;
}

Expand All @@ -69,6 +63,9 @@ public function setGenerator($generator)
*/
public function getGenerator()
{
if (is_null($this->generator) && class_exists('\Faker\Factory')) {
$this->generator = Factory::create();
}
return $this->generator;
}

Expand Down

0 comments on commit 49e7143

Please sign in to comment.