AbstractDataField   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A __construct() 0 6 2
A transform() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogosPopulate\Database;
6
7
abstract class AbstractDataField implements DataFieldInterface
8
{
9
    /** @var callable */
10
    private $transformFunction;
11
12
    /**
13
     * @param callable|null $transformFunction
14
     */
15 411
    public function __construct(private readonly string $name, callable $transformFunction = null)
16
    {
17 411
        if (null === $transformFunction) {
18 373
            $transformFunction = fn ($input): string => trim((string) $input);
19
        }
20 411
        $this->transformFunction = $transformFunction;
21
    }
22
23 399
    public function name(): string
24
    {
25 399
        return $this->name;
26
    }
27
28 231
    public function transform($input)
29
    {
30
        /** @var scalar $value */
31 231
        $value = call_user_func($this->transformFunction, $input);
32 230
        return $value;
33
    }
34
}
35