Completed
Push — master ( 969ba5...87cf68 )
by Przemysław eRIZ
02:24
created

GeneratorChain::getDefaultGeneratorsSet()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
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
    public function __construct($generators = [])
20
    {
21
        if (!$generators) {
22
            $generators = self::getDefaultGeneratorsSet();
23
        }
24
25
        foreach ($generators as $d) {
26
            $this->addGenerator($d);
27
        }
28
    }
29
30
    public function addGenerator(GeneratorInterface $detector)
31
    {
32
        $this->generators[] = $detector;
33
    }
34
35
    /**
36
     * @return GeneratorInterface[];
37
     */
38
    public static function getDefaultGeneratorsSet()
39
    {
40
        $result = [
41
            new TypedGenerator(),
42
        ];
43
44
        if (class_exists(Constraint::class)) {
45
            $result[] = new AssertGenerator();
46
        }
47
48
        $result[] = new RecursiveGenerator();
49
        $result[] = new FakerGenerator();
50
        $result[] = new PhpDocGenerator();
51
        $result[] = new LastResortGenerator();
52
53
        return $result;
54
    }
55
56
    public function getValueForField(
57
        FieldMetadata $field, FakeMock $fakemock
58
    ) {
59
        foreach ($this->generators as $d) {
60
            $result = $d->generateForProperty($field, $fakemock);
61
            if (!is_null($result)) {
62
                return $result;
63
            }
64
        }
65
66
        return null;
67
    }
68
}
69