From e97a020b4696459b39223c631cb7b94454a3c72b Mon Sep 17 00:00:00 2001 From: IN Date: Wed, 1 Mar 2017 12:12:32 +0300 Subject: [PATCH] Fallback to faker in __construct --- src/Anonymizer.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Anonymizer.php b/src/Anonymizer.php index b77fc48..2b51a57 100644 --- a/src/Anonymizer.php +++ b/src/Anonymizer.php @@ -4,7 +4,6 @@ use Arrilot\DataAnonymization\Database\DatabaseInterface; use Exception; -use Faker\Factory; class Anonymizer { @@ -16,7 +15,7 @@ class Anonymizer protected $database; /** - * Generator object (e.g faker). + * Generator object (e.g \Faker\Factory). * * @var mixed */ @@ -38,6 +37,11 @@ class Anonymizer public function __construct(DatabaseInterface $database, $generator = null) { $this->database = $database; + + if (is_null($generator) && class_exists('\Faker\Factory')) { + $generator = \Faker\Factory::create(); + } + if (!is_null($generator)) { $this->setGenerator($generator); } @@ -53,6 +57,7 @@ public function __construct(DatabaseInterface $database, $generator = null) public function setGenerator($generator) { $this->generator = $generator; + return $this; } @@ -63,9 +68,6 @@ public function setGenerator($generator) */ public function getGenerator() { - if (is_null($this->generator) && class_exists('\Faker\Factory')) { - $this->generator = Factory::create(); - } return $this->generator; }