Skip to content

Commit

Permalink
update to anteris-dev/faker-map 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
morrislaptop committed Jan 27, 2022
1 parent 8167a34 commit 7eec2ba
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
],
"require": {
"php": "^8.0",
"anteris-dev/faker-map": "^1.1",
"anteris-dev/faker-map": "^2.0",
"fakerphp/faker": "^1.13",
"symfony/property-access": "^5.2",
"symfony/property-info": "^5.2",
Expand Down
18 changes: 10 additions & 8 deletions src/PropertyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ class PropertyFactory
{
protected PhpDocExtractor $phpDocExtractor;
protected static array $providers = [];
private FakerMap $fakerMap;

public function __construct()
public function __construct(?FakerMap $fakerMap = null)
{
$this->phpDocExtractor = new PhpDocExtractor();
$this->fakerMap = $fakerMap ?? FakerMap::new();
}

public static function new(): self
Expand All @@ -33,12 +35,12 @@ public function make(ReflectionProperty $property)

// If a provider was registered to handle this type, pass off to that.
if (isset(static::$providers[$type])) {
return static::$providers[$type](new FakerMap, $property);
return static::$providers[$type](FakerMap::new(), $property);
}

// We will try to generate a property that matches what the property name
// indicates it expects. (e.g. $firstName would have "John")
$faker = FakerMap::closest($property->getName());
$faker = $this->fakerMap->closest($property->getName());

// If the property was type cast, we will ensure the returned type is
// what the property expects. Otherwise we will fallback on a value based
Expand Down Expand Up @@ -122,19 +124,19 @@ protected function createPropertyOfType(string $type)

switch ($type) {
case 'array':
return FakerMap::words();
return FakerMap::faker()->words();

case 'bool':
return FakerMap::boolean();
return FakerMap::faker()->boolean();

case 'int':
return FakerMap::randomDigit();
return FakerMap::faker()->randomDigit();

case 'float':
return FakerMap::randomFloat();
return FakerMap::faker()->randomFloat();
}

return FakerMap::word();
return FakerMap::faker()->word();
}

protected function createPropertyOfRandomType()
Expand Down

0 comments on commit 7eec2ba

Please sign in to comment.