ChainSplitFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 8 2
A configureValidator() 0 6 1
A __construct() 0 4 1
1
<?php
2
3
namespace Oliverde8\Component\PhpEtl\Builder\Factories;
4
5
use Oliverde8\Component\PhpEtl\ChainBuilder;
6
use Oliverde8\Component\PhpEtl\ChainOperation\ChainOperationInterface;
7
use Symfony\Component\Validator\Constraint;
8
use Symfony\Component\Validator\Constraints as Assert;
9
10
class ChainSplitFactory extends AbstractFactory
11
{
12
    /** @var ChainBuilder */
13
    protected $builder;
14
15
    public function __construct(string $operation, string $class, ChainBuilder $builder)
16
    {
17
        parent::__construct($operation, $class);
18
        $this->builder = $builder;
19
    }
20
21
    /**
22
     * @inheritdoc
23
     */
24
    public function build(string $operation, array $options): ChainOperationInterface
25
    {
26
        $chainProcessors = [];
27
        foreach ($options['branches'] as $branch) {
28
            $chainProcessors[] = $this->builder->buildChainProcessor($branch);
29
        }
30
31
        return $this->create($chainProcessors);
32
    }
33
34
    protected function configureValidator(): Constraint
35
    {
36
        return new Assert\Collection([
37
            'branches' => [
38
                new Assert\Type(["type" => "array"]),
39
                new Assert\NotBlank(),
40
            ],
41
        ]);
42
    }
43
}