GeneratorChain::getValueForField()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 3
nc 3
nop 3
crap 3
1
<?php
2
3
namespace Er1z\FakeMock\Generator;
4
5
use Er1z\FakeMock\FakeMock;
6
use Er1z\FakeMock\Metadata\FieldMetadata;
7
use Symfony\Component\Validator\Constraint;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\Validator\Constraint was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
class GeneratorChain implements GeneratorChainInterface
10
{
11
    /**
12
     * @var GeneratorInterface[]
13
     */
14
    private $generators;
15
16
    /**
17
     * @param GeneratorInterface[] $generators
18
     */
19 78
    public function __construct($generators = [])
20
    {
21 78
        if (!$generators) {
22 70
            $generators = self::getDefaultGeneratorsSet();
23
        }
24
25 78
        foreach ($generators as $d) {
26 78
            $this->addGenerator($d);
27
        }
28 78
    }
29
30 78
    public function addGenerator(GeneratorInterface $detector)
31
    {
32 78
        $this->generators[] = $detector;
33 78
    }
34
35
    /**
36
     * @return GeneratorInterface[];
37
     */
38 74
    public static function getDefaultGeneratorsSet()
39
    {
40
        $result = [
41 74
            new TypedGenerator(),
42
        ];
43
44 74
        if (class_exists(Constraint::class)) {
45 57
            $result[] = new AssertGenerator();
46
        }
47
48 74
        $result[] = new RecursiveGenerator();
49 74
        $result[] = new FakerGenerator();
50 74
        $result[] = new PhpDocGenerator();
51 74
        $result[] = new LastResortGenerator();
52
53 74
        return $result;
54
    }
55
56 46
    public function getValueForField(
57
        FieldMetadata $field, FakeMock $fakemock, ?string $group = null
58
    ) {
59 46
        foreach ($this->generators as $d) {
60 46
            $result = $d->generateForProperty($field, $fakemock, $group);
61 46
            if (!is_null($result)) {
62 45
                return $result;
63
            }
64
        }
65
66 4
        return null;
67
    }
68
}
69