RuleTransformFactory::build()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
rs 10
c 1
b 0
f 0
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Oliverde8\Component\PhpEtl\Builder\Factories\Transformer;
6
7
use Oliverde8\Component\PhpEtl\Builder\Factories\AbstractFactory;
8
use Oliverde8\Component\PhpEtl\ChainOperation\ChainOperationInterface;
9
use Oliverde8\Component\RuleEngine\RuleApplier;
10
use Symfony\Component\Validator\Constraint;
11
use Symfony\Component\Validator\Constraints as Assert;
12
13
/**
14
 * Class RuleTransformFactory
15
 *
16
 * @author    de Cramer Oliver<[email protected]>
17
 * @copyright 2018 Oliverde8
18
 * @package Oliverde8\Component\PhpEtl\Builder\Factories\Transformer
19
 */
20
class RuleTransformFactory extends AbstractFactory
21
{
22
    /** @var RuleApplier */
23
    protected $ruleApplier;
24
25
    /**
26
     * RuleTransformFactory constructor.
27
     *
28
     * @param string $operation
29
     * @param string $class
30
     * @param RuleApplier $ruleApplier
31
     */
32
    public function __construct(string $operation, string $class, RuleApplier $ruleApplier)
33
    {
34
        parent::__construct($operation, $class);
35
        $this->ruleApplier = $ruleApplier;
36
    }
37
38
    /**
39
     * @inheritdoc
40
     */
41
    public function build(string $operation, array $options): ChainOperationInterface
42
    {
43
        return $this->create($this->ruleApplier, $options['columns'], $options['add']);
44
    }
45
46
    /**
47
     * @inheritdoc
48
     */
49
    protected function configureValidator(): Constraint
50
    {
51
        return new Assert\Collection([
52
            'columns' => [
53
                new Assert\Type(["type" => "array"]),
54
                new Assert\NotBlank(),
55
            ],
56
            'add' => new Assert\Type(["type" => "boolean"])
57
        ]);
58
    }
59
}