ChainGeneratorFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addFactory() 0 5 1
A getGenerator() 0 10 3
1
<?php
2
3
namespace WebnetFr\DatabaseAnonymizer\GeneratorFactory;
4
5
use WebnetFr\DatabaseAnonymizer\Exception\UnsupportedGeneratorException;
6
use WebnetFr\DatabaseAnonymizer\Generator\GeneratorInterface;
7
8
/**
9
 * Delegates the creation of the generator to one of the provided factories.
10
 *
11
 * @author Vlad Riabchenko <[email protected]>
12
 */
13
class ChainGeneratorFactory implements GeneratorFactoryInterface
14
{
15
    /**
16
     * Array of generator factories.
17
     *
18
     * @var GeneratorFactoryInterface[]
19
     */
20
    private $factories = [];
21
22
    /**
23
     * Add factory.
24
     *
25
     * @param GeneratorFactoryInterface $factory
26
     *
27
     * @return $this
28
     */
29
    public function addFactory(GeneratorFactoryInterface $factory): self
30
    {
31
        $this->factories[] = $factory;
32
33
        return $this;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function getGenerator(array $config): GeneratorInterface
40
    {
41
        foreach ($this->factories as $factory) {
42
            try {
43
                return $factory->getGenerator($config);
44
            } catch (UnsupportedGeneratorException $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
45
            }
46
        }
47
48
        throw new UnsupportedGeneratorException($config['generator'].' generator is not known');
49
    }
50
}
51