Skip to content

Commit

Permalink
Fallback to faker in __construct
Browse files Browse the repository at this point in the history
  • Loading branch information
arrilot committed Mar 1, 2017
1 parent 49e7143 commit e97a020
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Anonymizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Arrilot\DataAnonymization\Database\DatabaseInterface;
use Exception;
use Faker\Factory;

class Anonymizer
{
Expand All @@ -16,7 +15,7 @@ class Anonymizer
protected $database;

/**
* Generator object (e.g faker).
* Generator object (e.g \Faker\Factory).
*
* @var mixed
*/
Expand All @@ -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);
}
Expand All @@ -53,6 +57,7 @@ public function __construct(DatabaseInterface $database, $generator = null)
public function setGenerator($generator)
{
$this->generator = $generator;

return $this;
}

Expand All @@ -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;
}

Expand Down

0 comments on commit e97a020

Please sign in to comment.