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

PreprocessDataField   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 30
ccs 10
cts 10
cp 1
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 4 1
A getNextDataField() 0 3 1
A name() 0 3 1
A __construct() 0 4 1
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