Passed
Push — master ( 6cf998...fd9a38 )
by Carlos C
12:00 queued 13s
created

PreprocessDataField::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogosPopulate\Database;
6
7
class PreprocessDataField implements DataFieldInterface
8
{
9
    /** @var callable(scalar):scalar */
10
    private $preprocessFunction;
11
12
    private DataFieldInterface $nextDataField;
13
14
    /**
15
     * @param callable(scalar):scalar $preprocessFunction
16
     */
17 5
    public function __construct(callable $preprocessFunction, DataFieldInterface $nextDataField)
18
    {
19 5
        $this->preprocessFunction = $preprocessFunction;
20 5
        $this->nextDataField = $nextDataField;
21
    }
22
23 4
    public function name(): string
24
    {
25 4
        return $this->nextDataField->name();
26
    }
27
28 2
    public function transform($input)
29
    {
30 2
        $value = call_user_func($this->preprocessFunction, $input);
31 2
        return $this->nextDataField->transform($value);
32
    }
33
34 4
    public function getNextDataField(): DataFieldInterface
35
    {
36 4
        return $this->nextDataField;
37
    }
38
}
39