Completed
Push — master ( 294a52...07db0f )
by Przemysław eRIZ
03:25
created

Registry::getGeneratorForLocale()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Er1z\FakeMock\Faker;
4
5
use Er1z\FakeMock\Metadata\FieldMetadata;
6
use Faker\Factory;
7
use Faker\Generator;
8
use Faker\Guesser\Name;
9
10
class Registry implements RegistryInterface
11
{
12
    /**
13
     * @var Generator[]
14
     */
15
    protected $generators = [];
16
17 53
    public function getGeneratorForField(FieldMetadata $fieldMetadata)
18
    {
19 53
        return $this->getGeneratorForLocale($fieldMetadata->configuration->locale);
20
    }
21
22 73
    public function getGeneratorForLocale(?string $locale = null): Generator
23
    {
24 73
        $locale = $locale ?? Factory::DEFAULT_LOCALE;
25
26 73
        if (empty($this->generators[$locale])) {
27 73
            $this->generators[$locale] = $this->instantiate($locale);
28
        }
29
30 73
        return $this->generators[$locale];
31
    }
32
33 27
    public function getGuesserForLocale(?string $locale = null): Name
34
    {
35 27
        $generator = $this->getGeneratorForLocale($locale);
36
37 27
        return new Name($generator);
38
    }
39
40 73
    protected function instantiate($locale = null)
41
    {
42 73
        return Factory::create($locale ?? Factory::DEFAULT_LOCALE);
43
    }
44
}
45