Completed
Push — dev ( 45fb7c...bb4abf )
by Przemysław eRIZ
02:34
created

Registry::instantiate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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