AttachableGeneratorAbstract   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
eloc 8
dl 0
loc 31
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getGenerator() 0 8 3
A __construct() 0 3 2
1
<?php
2
3
namespace Er1z\FakeMock\Generator;
4
5
use Er1z\FakeMock\FakeMock;
6
use Er1z\FakeMock\Faker\Registry;
7
use Er1z\FakeMock\Metadata\FieldMetadata;
8
9
abstract class AttachableGeneratorAbstract implements GeneratorInterface
10
{
11
    /**
12
     * @var \Er1z\FakeMock\Generator\AssertGenerator\GeneratorInterface[]
13
     */
14
    protected $generators;
15
16
    /**
17
     * @var Registry
18
     */
19
    protected $fakerRegistry;
20
21 105
    public function __construct(?Registry $registry = null)
22
    {
23 105
        $this->fakerRegistry = $registry ?: new Registry();
24 105
    }
25
26
    abstract public function generateForProperty(
27
        FieldMetadata $field, FakeMock $fakemock, ?string $group = null
28
    );
29
30
    abstract protected function getGeneratorFqcn($simpleClassName);
31
32 27
    protected function getGenerator($assertClass)
33
    {
34 27
        if (empty($this->generators[$assertClass])) {
35 20
            $generatorFqcn = $this->getGeneratorFqcn($assertClass);
36 20
            $this->generators[$assertClass] = class_exists($generatorFqcn) ? new $generatorFqcn() : false;
37
        }
38
39 27
        return $this->generators[$assertClass];
40
    }
41
}
42