CsvFileWriterFactory::configureValidator()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 2
cp 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Oliverde8\Component\PhpEtl\Builder\Factories\Loader;
6
7
use Oliverde8\Component\PhpEtl\Builder\Factories\AbstractFactory;
8
use Oliverde8\Component\PhpEtl\ChainOperation\ChainOperationInterface;
9
use Oliverde8\Component\PhpEtl\Load\File\Csv;
10
use Symfony\Component\Validator\Constraint;
11
use Symfony\Component\Validator\Constraints as Assert;
12
13
/**
14
 * Class FileWriterFactory
15
 *
16
 * @author    de Cramer Oliver<[email protected]>
17
 * @copyright 2018 Oliverde8
18
 * @package Oliverde8\Component\PhpEtl\Builder\Factories\Loader
19
 */
20
class CsvFileWriterFactory extends AbstractFactory
21
{
22
    /**
23
     * @inheritdoc
24
     */
25
    protected function configureValidator(): Constraint
26
    {
27
        return new Assert\Collection([
28
            'file' => new Assert\NotBlank(),
29
        ]);
30
    }
31
32
    /**
33
     * @inheritdoc
34
     */
35
    protected function build($operation, $options): ChainOperationInterface
36
    {
37
        $tmp = tempnam(sys_get_temp_dir(), 'etl');
38
        return $this->create(new Csv($tmp), $options['file']);
39
    }
40
}
41