FakerGenerator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 13
dl 0
loc 29
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A generateForProperty() 0 17 3
1
<?php
2
3
namespace Er1z\FakeMock\Generator;
4
5
use Er1z\FakeMock\FakeMock;
6
use Er1z\FakeMock\Faker\Registry;
7
use Er1z\FakeMock\Faker\RegistryInterface;
8
use Er1z\FakeMock\Metadata\FieldMetadata;
9
10
class FakerGenerator implements GeneratorInterface
11
{
12
    /**
13
     * @var Registry
14
     */
15
    private $fakerRegistry;
16
17 86
    public function __construct(?RegistryInterface $generator = null)
18
    {
19 86
        $this->fakerRegistry = $generator ?? new Registry();
20 86
    }
21
22 47
    public function generateForProperty(FieldMetadata $field, FakeMock $fakemock, ?string $group = null)
23
    {
24 47
        if ($field->configuration->faker) {
25
            return
26 24
                $this->fakerRegistry->getGeneratorForField($field)->{$field->configuration->faker}(
27 24
                    ...(array) $field->configuration->arguments
28
                );
29
        }
30
        $format =
31 27
            $this->fakerRegistry->getGuesserForLocale($field->configuration->locale)
32 27
            ->guessFormat($field->property->getName());
33
34 27
        if ($format) {
35 12
            return $format();
36
        }
37
38 19
        return null;
39
    }
40
}
41