FakerGenerator::generateForProperty()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 17
ccs 9
cts 9
cp 1
rs 9.9332
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 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