RecursiveGenerator   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 11
dl 0
loc 31
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addClassMapping() 0 3 1
A __construct() 0 3 1
A generateForProperty() 0 14 3
1
<?php
2
3
namespace Er1z\FakeMock\Generator;
4
5
use Er1z\FakeMock\FakeMock;
6
use Er1z\FakeMock\Generator\RecursiveGenerator\ClassMapper;
7
use Er1z\FakeMock\Generator\RecursiveGenerator\ClassMapperInterface;
8
use Er1z\FakeMock\Metadata\FieldMetadata;
9
10
class RecursiveGenerator implements GeneratorInterface
11
{
12
    /**
13
     * @var ClassMapperInterface
14
     */
15
    protected $classMapper;
16
17 78
    public function __construct(?ClassMapperInterface $classMapper = null)
18
    {
19 78
        $this->classMapper = $classMapper ?? new ClassMapper();
20 78
    }
21
22 43
    public function generateForProperty(FieldMetadata $field, FakeMock $fakemock, ?string $group = null)
23
    {
24 43
        if (!$field->configuration->recursive) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $field->configuration->recursive of type boolean|null is loosely compared to false; this is ambiguous if the boolean can be false. You might want to explicitly use !== null instead.

If an expression can have both false, and null as possible values. It is generally a good practice to always use strict comparison to clearly distinguish between those two values.

$a = canBeFalseAndNull();

// Instead of
if ( ! $a) { }

// Better use one of the explicit versions:
if ($a !== null) { }
if ($a !== false) { }
if ($a !== null && $a !== false) { }
Loading history...
25 4
            return null;
26
        }
27
28 39
        $value = $this->classMapper->getObjectForField($field);
29 39
        if (!$value) {
30 39
            return null;
31
        }
32
33 8
        $value = $fakemock->fill($value);
34
35 8
        return $value;
36
    }
37
38 4
    public function addClassMapping(string $intefaceOrAbstractFqcn, string $targetFqcn)
39
    {
40 4
        $this->classMapper->addClassMapping($intefaceOrAbstractFqcn, $targetFqcn);
41 4
    }
42
}
43