AttachableGeneratorAbstract::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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